Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Marc Würth
@ravage84
What is your CLI command?
Michael Anderson
@manderson
With the command phpmd foo.php text unusedcode I get no response from the following code:
<?php

$foo = 42;
Marc Würth
@ravage84
<?php

$foo = 42;

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}
It doesn't note the first but the second unused variable...
I'm not sure this is whether the first one is in a global scope.
Michael Anderson
@manderson
I was just reading the documentation for the rules and I think you're correct about the global scope. the unusedcode ruleset refers to UnusedPrivateField, UnusedLocalVariable, UnusedPrivateMethod, and UnusedFormalParameter.
None of those sound like they would trigger on a global variable
Marc Würth
@ravage84
Yeah, probably.
Do you have a lot of code in global scope?
Even if we had such a rule, like I said, it would be kind of problematic to be really sure that a varaible is really unused.
Michael Anderson
@manderson
Not necessarily. I was just mocking up some code to allow me to play with phpmd and was confused when I wasn't seeing the responses I was expecting.
I think that clears up my issues for now. Thanks a lot for your assistance.
Marc Würth
@ravage84
Just use PHPMD with a real project, so you get real violation metrics. That is much more useful and you have relatable code.
You are welcome. Hope you find use in it.
By the way, where did you hear about PHPMD?
Michael Anderson
@manderson
I was looking through the phing documentation and it makes reference to phpmd. And since I've been considering getting something to evaluate code quality I decided to take a look.
Marc Würth
@ravage84
Thanks.
panayotisk
@panayotisk
Hi all. I just installed latest phpmd on windows through composer and I just can't make it work.
Mathias STRASSER
@roukmoute
what's happening?
panayotisk
@panayotisk
"@php_bin@"' is not recognized as an internal or external command,
operable program or batch file.
I want to install the vs code extension later, but I need to see it working first.
Mathias STRASSER
@roukmoute
Have you PHP path specified in your env?
panayotisk
@panayotisk
No
How should I do this?
What I did was:
{
"require-dev": {
"phpmd/phpmd" : "@stable"
}
}
and then composer update
and composer install
Kyle
@kylekatarnls
Quick note: running composer update already install the dependencies no need for composer install
panayotisk
@panayotisk
yes, thank you for this tip!
Kyle
@kylekatarnls
Then how do you run PHPMD then? .\vendor\bin\phpmd maybe?
Mathias STRASSER
@roukmoute
if you write just php -v in your console it does work right?
panayotisk
@panayotisk
If I write php -v it shows
PHP 7.1.20 (cli) (built: Jul 19 2018 08:59:55) ( ZTS MSVC14 (Visual C++ 2015) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
Aha @Kyle I was switching to wrong directory
I tried from .\vendor\phpmd\phpmd\src\bin
and from there it was not working
Kyle
@kylekatarnls
This is the source file, @phpbin@ is transformed according to the OS during installation process and copied into your common vendor/bin directory.
That's the reason.
panayotisk
@panayotisk
I am new to all this... Thank you guys, I guess I will manage to make it work now.
You have been very helpful
Kyle
@kylekatarnls
If you setup %APPDATA%\Composer\vendor\bin in your PATH environment variable, you will be able to install such composer CLI package with composer global require phpmd then to simply call phpmd src ruleset.xml... in your console if you want.
panayotisk
@panayotisk
Is global install considered good practice? I had not try it before.
Kyle
@kylekatarnls
Not on your remote server (there prefer enclosing installations) but in a local development environment, it would allow you to check any PHP source that is not necessarily in a project. It's the same than having PHPUnit or PHP itself available globally in your CLI. And you still can call .\vendor\bin\phpmd to use the specific PHPMD version of a project.
panayotisk
@panayotisk
Great help, thank you!
Juris Malinens
@jmalinens
hi!
http://static.phpmd.org/php/latest/phpmd.phar looks like static.phpmd.org is down
Kyle
@kylekatarnls
Hi, see this issue: phpmd/phpmd#619
Juris Malinens
@jmalinens
thanks @kylekatarnls
Anders Jenbo
@AJenbo
@kylekatarnls @manderson the issues with count() is because invalid input to the function has been deprecated since PHP 7.2. This is one of the issues I'm working to eradicate from the codebase (mainly on the PDepend side of things at the moment).