Error using PHP_Depend and PHP_PMD - sonarqube

I have a problem using php Depend and PMD. When I use:
pdepend --summary-xml=/home/<mydirectory>/.sonar/pdepend.xml --suffix=php,php3,php4,php5,phtml,inc /home/<mydirectory>
this is the result:
Parsing...
.................................................. 1260
........................PHP Catchable fatal error: Argument 1 passed to PHP_Depend_Parser_UnexpectedTokenException::__construct() must be an instance of PHP_Depend_Token, integer given, called in /usr/share/php/PHP/Depend/Parser.php on line 5444 and defined in /usr/share/php/PHP/Depend/Parser/UnexpectedTokenException.php on line 70
PHP Stack trace:
PHP 1. {main}() /usr/bin/pdepend:0
PHP 2. PHP_Depend_TextUI_Command::main() /usr/bin/pdepend:78
PHP 3. PHP_Depend_TextUI_Command->run() /usr/share/php/PHP/Depend/TextUI/Command.php:679
PHP 4. PHP_Depend_TextUI_Runner->run() /usr/share/php/PHP/Depend/TextUI/Command.php:206
PHP 5. PHP_Depend->analyze() /usr/share/php/PHP/Depend/TextUI/Runner.php:331
PHP 6. PHP_Depend->performParseProcess() /usr/share/php/PHP/Depend.php:306
PHP 7. PHP_Depend_Parser->parse() /usr/share/php/PHP/Depend.php:560
PHP 8. PHP_Depend_Parser->parseOptionalStatement() /usr/share/php/PHP/Depend/Parser.php:370
PHP 9. PHP_Depend_Parser->parseIfStatement() /usr/share/php/PHP/Depend/Parser.php:5474
PHP 10. PHP_Depend_Parser->parseStatementBody() /usr/share/php/PHP/Depend/Parser.php:3195
PHP 11. PHP_Depend_Parser->parseStatement() /usr/share/php/PHP/Depend/Parser.php:2320
PHP 12. PHP_Depend_Parser_UnexpectedTokenException->__construct() /usr/share/php/PHP/Depend/Parser.php:5444
The same happens with:
phpmd /home/<mydirectory> xml /home/<mydirectory>/Sonar_Way_php.xml
PHP Catchable fatal error: Argument 1 passed to PHP_Depend_Parser_UnexpectedTokenException::__construct() must be an instance of PHP_Depend_Token, integer given, called in /usr/share/php/PHP/Depend/Parser.php on line 5444 and defined in /usr/share/php/PHP/Depend/Parser/UnexpectedTokenException.php on line 70
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpmd:0
PHP 2. PHP_PMD_TextUI_Command::main() /usr/bin/phpmd:48
PHP 3. PHP_PMD_TextUI_Command->run() /usr/share/php/PHP/PMD/TextUI/Command.php:151
PHP 4. PHP_PMD->processFiles() /usr/share/php/PHP/PMD/TextUI/Command.php:129
PHP 5. PHP_PMD_Parser->parse() /usr/share/php/PHP/PMD.php:203
PHP 6. PHP_Depend->analyze() /usr/share/php/PHP/PMD/Parser.php:128
PHP 7. PHP_Depend->performParseProcess() /usr/share/php/PHP/Depend.php:306
PHP 8. PHP_Depend_Parser->parse() /usr/share/php/PHP/Depend.php:560
PHP 9. PHP_Depend_Parser->parseOptionalStatement() /usr/share/php/PHP/Depend/Parser.php:370
PHP 10. PHP_Depend_Parser->parseIfStatement() /usr/share/php/PHP/Depend/Parser.php:5474
PHP 11. PHP_Depend_Parser->parseStatementBody() /usr/share/php/PHP/Depend/Parser.php:3195
PHP 12. PHP_Depend_Parser->parseStatement() /usr/share/php/PHP/Depend/Parser.php:2320
PHP 13. PHP_Depend_Parser_UnexpectedTokenException->__construct() /usr/share/php/PHP/Depend/Parser.php:5444
¿Any sugestion? Thanks.

It's a bug of pdepend and pmd. In /usr/share/php/PHP/Depend/parser.php I changed:
private function parseStatement()
{
if (null === ($stmt = $this->parseOptionalStatement())) {
throw new PHP_Depend_Parser_UnexpectedTokenException(
$this->tokenizer->next(),
$this->sourceFile->getFileName()
);
}
return $stmt;
}
for this:
private function parseStatement()
{
if (null === ($stmt = $this->parseOptionalStatement())) {
throw new PHP_Depend_Parser_UnexpectedTokenException(
new PHP_Depend_Token,
$this->sourceFile->getFileName()
);
}
return $stmt;
}
I obtain only warnings and the process continue:
PHP Warning: Missing argument 1 for PHP_Depend_Token::__construct(), called in /usr/share/php/PHP/Depend/Parser.php on line 5442 and defined in /usr/share/php/PHP/Depend/Token.php on line 121
We can wait next upgrade ;)

Related

Magento when enabling log through command line getting error

In my Magento application when I try to enable logging in command line using below code
# bin/magento setup:config:set –enable-debug-logging=true
I am getting the error
PHP Fatal error: Declaration of Magenest\SagePay\Helper\Logger::debug($message, array $context = []) must be compatible with Monolog\Logger::debug($message, array $context = []): void in /vendor/magenest/module-sage-pay-basic/Helper/Logger.php on line 49

Error when i try to create livewire component

I've installed laravel livewire on a Laravel 8 project, ad when i run the command php artisan make:livewire table the terminal shows this error:
ArgumentCountError
Too few arguments to function Illuminate\Support\Str::finish(), 1 passed in /Applications/MAMP/htdocs/cuoreLaravel/vendor/livewire/livewire/src/helpers.php on line 12 and exactly 2 expected
at vendor/laravel/framework/src/Illuminate/Support/Str.php:235
231▕ * #param string $value
232▕ * #param string $cap
233▕ * #return string
234▕ */
➜ 235▕ public static function finish($value, $cap)
236▕ {
237▕ $quoted = preg_quote($cap, '/');
238▕
239▕ return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
+17 vendor frames
18 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
I've followed all the documentation installation steps, but I don't understand what the problem is.
I hope someone can help me :-) thanks
This happened to me after a fresh install of Livewire. Running php artisan optimize fixed it in my case. I have not found the exact reason, but I suspect some of the Livewire config needed to be included in the config cache first.
So either optimize, or clear the cached config completely.

Call to undefined function Illuminate\Support\random_bytes()

I receive this error message:
FatalErrorException in Str.php line 243: Call to undefined function Illuminate\Support\random_bytes()
public static function randomBytes($length = 16) {
return random_bytes($length);
}
line 243: return random_bytes($length);
I do not understand what's wrong since a working version Laravel offline that extract online.
It does not work online though. I wonder why?
random_bytes is a PHP 7 function.
I'm assuming that your offline/development stack has PHP 7 installed but not online/production.
Confirm your hosting for PHP 7 installed.

Laravel Missing argument 4 for Dingo\Blueprint\Blueprint::generate()

[ErrorException]
Missing argument 4 for Dingo\Blueprint\Blueprint::generate(), called in /Applications/XAMPP/xamppfiles/htdocs/api/vendor/dingo/api/src/Console/Command/Docs.php
on line 95 and defined
Exception trace:
() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/dingo/blueprint/src/Blueprint.php:83
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/dingo/blueprint/src/Blueprint.php:83
Dingo\Blueprint\Blueprint->generate() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/dingo/api/src/Console/Command/Docs.php:95
Dingo\Api\Console\Command\Docs->handle() at n/a:n/a
call_user_func_array() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
Illuminate\Container\Container->call() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:150
Illuminate\Console\Command->execute() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/symfony/console/Command/Command.php:256
Symfony\Component\Console\Command\Command->run() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:136
Illuminate\Console\Command->run() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/symfony/console/Application.php:841
Symfony\Component\Console\Application->doRunCommand() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/symfony/console/Application.php:189
Symfony\Component\Console\Application->doRun() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/symfony/console/Application.php:120
Symfony\Component\Console\Application->run() at /Applications/XAMPP/xamppfiles/htdocs/api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107
Illuminate\Foundation\Console\Kernel->handle() at /Applications/XAMPP/xamppfiles/htdocs/api/artisan:36
This has been resolved in the master branch of Dingo API, try pulling this into your development.
IncludePath wasn't included as the 4th parameter in Dingo\Blueprint\Blueprint::generate() function call. Here is the link to the updated file on the master branch.
Kevin's solution does not work for me. ( with laravel 5.1 )
after replacement of Docs.php, I got errors with Blueprint class.
So:
In place of Kevin's solution. I found a simple one which works in one second.
:)
modify file:
vendor/dingo/api/src/Console/Command/Docs.php
$contents = $this->blueprint->generate($this->getControllers(), $this->argument('name'), $this->argument('version'));
with the following code:
$contents = $this->blueprint->generate($this->getControllers(), $this->argument('name'), $this->argument('version'),'');
by just adding a ,'' at the end of the function call, the place of the fourth argument.

Laravel 4 - Warning: Illegal offset type in isset or empty in \bootstrap\compiled.php

I'm having a hard time installing Laravel 4 on Windows 8 + Xampp.
Here's the setup:
- Xampp 1.8.1
- Composer is installed globally
I install Laravel with the usual "composer create-project laravel/laravel projectname". It installs fine.
But when I navigate to the public folder of the framework, I get dozens of Warning: Illegal offset type in isset or empty in \bootstrap\compiled.php errors.
On lines : 439, 221, 137, 154. The 4 errors are repeated indefinitely until the request times out.
Troubleshooting done so far:
- Tried on 2 seperate machines with the same setup.
- Re-ran Composer update.
- Instead of using create-project, I downloaded the framework and ran Composer install.
- Tried to setup up virtual hosts instead of accessing localhost/projectname/public.
- Searched online for 2 hours. Read every Laravel 4 install tutorial.
Any clues on what I might be doing wrong?
Thanks
-- EDIT --
Here are the lines causing the problem inside of compiled.php
Line 137 section :
$abstract = $this->getAlias($abstract);
if (isset($this->instances[$abstract])) {
return $this->instances[$abstract];
}
Line 154 section :
protected function getConcrete($abstract)
{
if (!isset($this->bindings[$abstract])) {
return $abstract;
} else {
return $this->bindings[$abstract]['concrete'];
}
}
Line 221 section :
protected function getAlias($abstract)
{
return isset($this->aliases[$abstract]) ? $this->aliases[$abstract] : $abstract;
}
Line 439 section :
public function make($abstract, $parameters = array())
{
if (isset($this->deferredServices[$abstract])) {
$this->loadDeferredProvider($abstract);
}
return parent::make($abstract, $parameters);
}
-- NEW FIND --
Using Wampserver works, instead of using Xampp.
Encountered the same error when using Xampp. I fixed it by disabling the eAccelerator extension in php.ini. Try commenting out the following line: zend_extension = "path\to\xampp\php\ext\php_eaccelerator_ts.dll" in your php.ini file.

Resources