php-cli icon indicating copy to clipboard operation
php-cli copied to clipboard

Access to undefined property

Open pattisahusiwa opened this issue 4 years ago • 9 comments

$verbosity is not defined.

https://github.com/adhocore/php-cli/blob/c17fdec05954b3bd2df49adff56284a511dd1083/src/Input/Command.php#L92

pattisahusiwa avatar Oct 09 '20 13:10 pattisahusiwa

should not happen, because of null coalesce

adhocore avatar Oct 09 '20 14:10 adhocore

Unit test failed when adding $verbosity to Command class

pattisahusiwa avatar Oct 09 '20 14:10 pattisahusiwa

hmm verbosity, help, version etc are reserved members, best to use something else

adhocore avatar Oct 09 '20 15:10 adhocore

These errors are reported by phpstan with error level 3. You can check the changes in my fork.

 ------ -----------------------------------------------------------------------------------------------------------
  Line   src/Application.php
 ------ -----------------------------------------------------------------------------------------------------------
  260    Method Ahc\Cli\Application::parse() should return Ahc\Cli\Input\Command but returns Ahc\Cli\Input\Parser.
 ------ -----------------------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------------------------------
  Line   src/Helper/Shell.php
 ------ -------------------------------------------------------------------------------
  181    Property Ahc\Cli\Helper\Shell::$processStartTime (int) does not accept float.
 ------ -------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------
  Line   src/Input/Command.php
 ------ --------------------------------------------------------------------
  92     Access to an undefined property Ahc\Cli\Input\Command::$verbosity.
 ------ --------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------
  Line   src/Input/Parser.php
 ------ --------------------------------------------------------------------------------
  248    Array (array<Ahc\Cli\Input\Argument>) does not accept Ahc\Cli\Input\Parameter.
 ------ --------------------------------------------------------------------------------

 ------ -------------------------------------------------------------
  Line   tests/Output/ColorTest.php
 ------ -------------------------------------------------------------
  34     Call to an undefined method Ahc\Cli\Output\Color::alert().
  66     Call to an undefined method Ahc\Cli\Output\Color::bold().
  71     Call to an undefined method Ahc\Cli\Output\Color::bgRed().
  76     Call to an undefined method Ahc\Cli\Output\Color::purple().
  84     Call to an undefined method Ahc\Cli\Output\Color::random().
 ------ -------------------------------------------------------------

 ------ ----------------------------------------------------------------
  Line   tests/Output/WriterTest.php
 ------ ----------------------------------------------------------------
  30     Access to an undefined property Ahc\Cli\Output\Writer::$error.
  46     Access to an undefined property Ahc\Cli\Output\Writer::$bold.
  56     Call to an undefined method Ahc\Cli\Output\Writer::clear().
 ------ ----------------------------------------------------------------

 [ERROR] Found 12 errors

pattisahusiwa avatar Oct 09 '20 15:10 pattisahusiwa

When adding $verbosity property to Command or Parser class, this test fails because $p->verbosity = 0. To continue working on phpstan, this issue needs to be addressed.

https://github.com/adhocore/php-cli/blob/c17fdec05954b3bd2df49adff56284a511dd1083/tests/Input/DefaultOptionTest.php#L53-L58

pattisahusiwa avatar Oct 09 '20 16:10 pattisahusiwa

hmm some of that is happening because we have code without declare strict_types.

adhocore avatar Oct 10 '20 00:10 adhocore

i'm on a vacation for few more days, will take time to look into it

adhocore avatar Oct 10 '20 14:10 adhocore

What's new?

pattisahusiwa avatar Jan 13 '21 04:01 pattisahusiwa

nothing new :)

adhocore avatar Jan 13 '21 06:01 adhocore