When I run codesniffer for magento2 extension by following the doc - https://developer.adobe.com/commerce/php/coding-standards/
From magento root directory I run
vendor/bin/phpcbf --standard=Magento2 ./app/code/Test/Module
I get the following error
PHP Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: The $start position for getTokensAsString() must exist in the token stack in /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Files/File.php:2112
Stack trace:
#0 /home/cloudpanel/htdocs/magento2.mgt/vendor/magento/magento-coding-standard/Magento2/Sniffs/Functions/FunctionsDeprecatedWithoutArgumentSniff.php(66): PHP_CodeSniffer\Files\File->getTokensAsString()
#1 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Functions\FunctionsDeprecatedWithoutArgumentSniff->process()
#2 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Fixer.php(174): PHP_CodeSniffer\Files\LocalFile->process()
#4 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport()
#6 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Runner.php(657): PHP_CodeSniffer\Reporter->cacheFileReport()
#7 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile()
#8 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Runner.php(200): PHP_CodeSniffer\Runner->run()
#9 /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/bin/phpcbf(18): PHP_CodeSniffer\Runner->runPHPCBF()
#10 /home/cloudpanel/htdocs/magento2.mgt/vendor/bin/phpcbf(120): include('...')
#11 {main}
thrown in /home/cloudpanel/htdocs/magento2.mgt/vendor/squizlabs/php_codesniffer/src/Files/File.php on line 2112
my php version is
PHP 8.1.8 (cli) (built: Jul 8 2022 07:08:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.8, Copyright (c) Zend Technologies
with Zend OPcache v8.1.8, Copyright (c), by Zend Technologies
I am using Magento 2.4.4
What is the issue here?
Related
Setup:di compile throws and error after upgrade
My environment is ubuntu 18, Magento CE 2.4.3 and the error is as below. Tried deleting the composer.lock, removing the vendor folder, running composer update and composer install. Error persists and compile fails. What else can I try?
1/9 [===>------------------------] 11% < 1 sec 145.0 MiBsyntax error, unexpected '=', expecting variable (T_VARIABLE)#0 /var/www/html/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile()
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#2 [internal function]: spl_autoload_call()
#3 /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(134): class_exists()
#4 /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(117): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->includeClass()
#5 /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(87): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->extract()
#6 /var/www/html/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php(61): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->getList()
#7 /var/www/html/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php(56): Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator->doOperation()
#8 /var/www/html/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php(216): Magento\Setup\Module\Di\App\Task\Manager->process()
#9 /var/www/html/vendor/symfony/console/Command/Command.php(255): Magento\Setup\Console\Command\DiCompileCommand->execute()
#10 /var/www/html/vendor/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#11 /var/www/html/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#12 /var/www/html/vendor/magento/framework/Console/Cli.php(115): Symfony\Component\Console\Application->doRun()
#13 /var/www/html/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun()
#14 /var/www/html/bin/magento(23): Symfony\Component\Console\Application->run()
#15 {main}
Tried forcing php 7.4.27 and php 7.4.21 in my composer.json
name : psr/log
descrip. : Common interface for logging libraries
keywords : log, psr, psr-3
versions : * 1.1.4
type : library
license : MIT License (MIT) (OSI approved)
https://spdx.org/licenses/MIT.html#licenseText
homepage : https://github.com/php-fig/log
source : [git] https://github.com/php-fig/log.git
d49695b909c3b7628b6289db5479a1c204601f11
dist : [zip] https://api.github.com/repos/php
fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11
d49695b909c3b7628b6289db5479a1c204601f11
path : /var/www/html/vendor/psr/log
names : psr/log
support
source : https://github.com/php-fig/log/tree/1.1.4
autoload
psr-4
Psr\Log\ => Psr/Log/
requires
php >=5.3.0
A friend helped me trace the error back to an actual syntax error in
app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter/Price.php on line 156
isLast needs to be $isLast
Hi there I'm try to connect mongo DB(Version 3.4.18) using CakePHP (version 3.5.1) with Apache server on PHP (7.2.4) and facing below error
2019-07-01 10:41:09 Error: [Error] Class 'MongoClient' not found in E:\xampp\htdocs\myproject\src\Controller\AppController.php on line 142
Request URL: /
Stack Trace:
#0 E:\xampp\htdocs\myproject\src\Controller\PagesController.php(219): App\Controller\AppController->__connectmongodb()
#1 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Controller\Controller.php(441): App\Controller\PagesController->home()
#2 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(119): Cake\Controller\Controller->invokeAction()
#3 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(93): Cake\Http\ActionDispatcher->_invoke(Object(App\Controller\PagesController))
#4 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\BaseApplication.php(103): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#5 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#6 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Routing\Middleware\RoutingMiddleware.php(107): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#7 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#8 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Routing\Middleware\AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#9 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#10 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Error\Middleware\ErrorHandlerMiddleware.php(93): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#11 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#12 E:\xampp\htdocs\myproject\vendor\cakephp\debug_kit\src\Middleware\DebugKitMiddleware.php(52): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#13 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\Runner.php(65): DebugKit\Middleware\DebugKitMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#14 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#15 E:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Http\Server.php(81): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#16 E:\xampp\htdocs\myproject\webroot\index.php(40): Cake\Http\Server->run()
#17 {main}
for mongo db connection trying below code
public function __connectmongodb()
{
$m = new \MongoClient('mongodb://localhost:27017');
return $db = $m->myDb;
}
Note: I have to do this in mongo DB(Version 3.4.18) using CakePHP (version 3.5.1) with Apache server on PHP (7.2.4) these specific versions
UPDATE - we trying on windows using php_mongodb-1.4.0-7.2-ts-vc15-x64 this .dll file
php_mongodb-1.4.0-7.2-ts-vc15-x64 is the "new" or rather the only officially supported driver https://pecl.php.net/package/mongodb. Its usage is documented here https://www.php.net/manual/en/set.mongodb.php and is basically uses MongoDB\Driver\Manager.
The MongoClient is from legacy and deprecated long time ago driver: https://pecl.php.net/package/mongo. It is documented here https://www.php.net/manual/en/book.mongo.php
There is no official support of the legacy driver for PHP 7: https://jira.mongodb.org/browse/PHP-1474
Last time the legacy driver was listed on https://docs.mongodb.com/ecosystem/drivers/php/ back in February 2018. By then it was claimed to be compatible with mongodb server v2.4, v2.6, and v3.0 with no compatibility with databases v3.2+.
The same February 2018 mongodb v3.0 retired. Support of Mongodb v3.2 has been dropped later in 2018 and v3.4 is counting its last months of support till January 2020.
Long story short, no you don't actually want this using MongoClient.
When I opened the project,I get back this error message :
Fatal error: Uncaught Error: Class 'String' not found in /dev/local/lib/Cake/Utility/Debugger.php:339 Stack trace: #0 /dev/local/lib/Cake/Utility/Debugger.php(741): Debugger::trace(Array) #1 /dev/local/lib/Cake/Error/ErrorHandler.php(219): Debugger->outputError(Array) #2 /dev/local/lib/Cake/Core/App.php(565): ErrorHandler::handleError(2, 'Declaration of ...', '/dev/local...', 25, Array) #3 /dev/local/lib/Cake/Core/App.php(565): include() #4 [internal function]: App::load('TradeLog') #5 [internal function]: spl_autoload_call('TradeLog') #6 /dev/local/lib/Cake/Utility/ClassRegistry.php(145): class_exists('TradeLog') #7 /dev/local/app/Controller/Component/UserComponent.php(61): ClassRegistry::init('TradeLog') #8 /dev/local/app/Controller/Component/PlatformAgentComponent.php(24): UserComponent->__construct(Object(ComponentCollection), Array) #9 /Us in /dev/local/lib/Cake/Utility/Debugger.php on line 339
The newly configured environment in mac os.
When I paste the project into a folder, this error occurs. What's the matter?
This is a compatibility issue between Cakephp 2.4 and PHP7 (because string became reserved word in PHP7, so Cakephp cannot use it as a class name). Using of newer version of Cakephp is suggested. Also downgrading your PHP to 5.6 could solve the problem.
You need to upgrade to CakePHP > 2.8 which is compatible with PHP7
https://github.com/cakephp/cakephp/releases/2.8.0
I am attempting to run a build on Jenkins running Ubuntu 14.04. My PHPUnit is crashing with the below error message, but there doesn't seem to much out there regarding this error. My xdebug appears to be loading correctly. I am running PHPUnit v4.8.10.
When I try to run phpunit via the command line directly, it just hangs and doesn't return. What am I missing?
phpunit:
[phpunit] PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(//proc/tty/driver): failed to open dir: Permission denied' in /var/lib/jenkins/jobs/Some other job/workspace/vendor/phpunit/php-file-iterator/src/Factory.php:66
[phpunit] Stack trace:
[phpunit] #0 [internal function]: RecursiveDirectoryIterator->__construct('//proc/tty/driv...', 512)
[phpunit] #1 [internal function]: RecursiveDirectoryIterator->getChildren()
[phpunit] #2 [internal function]: FilterIterator->rewind()
[phpunit] #3 /var/lib/jenkins/jobs/Some other job/workspace/vendor/phpunit/php-file-iterator/src/Factory.php(66): AppendIterator->append(Object(File_Iterator))
[phpunit] #4 /var/lib/jenkins/jobs/Some other job/workspace/vendor/phpunit/php-file-iterator/src/Facade.php(38): File_Iterator_Factory->getFileIterator(Array, '.php', '', Array)
[phpunit] #5 /var/lib/jenkins/jobs/Some other job/workspace/vendor/phpunit/php-code-coverage/src/CodeCoverage/Filter.php(112): File_Iterator_Facade->getFilesAsArray('/', '.php', '')
[phpunit] #6 /var/lib/jenkins/jobs/Some other job/workspace/vend in /var/lib/jenkins/jobs/Some other job/workspace/vendor/phpunit/php-file-iterator/src/Factory.php on line 66
BUILD FAILED
/var/lib/jenkins/jobs/Some other job/workspace/build.xml:169: exec returned: 255
PHP Info:
PHP 5.5.9-1ubuntu4.13 (cli) (built: Sep 29 2015 15:24:49)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
The problem was with my whitelisting inside my phpunit.xml. As you can see in the <directory> tag, I was telling my code coverage to start at the root of the server! Which is how it ended up looking through my sockets and getting caught somewhere it shouldn't have been.
To resolve this, change the <directory suffix=".php">/</directory> below to <directory suffix=".php">./</directory> so the code coverage only looks through your project directory.
The old filter:
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">/</directory>
<exclude>
<file>bootstrap/autoload.php</file>
</exclude>
</whitelist>
</filter>
I receive that error when try send e-mail with CakePHP 2.3.0.
My Cloud configuration is:
PHP 5.4
Apache 2.2
MySQL 5.5
CakePHP 2.3.0
Sorry about my english.
2013-03-06 09:15:05 Error: [SocketException] Permission denied
Request URL: /notifications/sendContact
Stack Trace:
#0 /var/www/html/site/lib/Cake/Network/Email/SmtpTransport.php(96): CakeSocket->connect()
#1 /var/www/html/site/lib/Cake/Network/Email/SmtpTransport.php(60): SmtpTransport->_connect()
#2 /var/www/html/site/lib/Cake/Network/Email/CakeEmail.php(1065): SmtpTransport->send(Object(CakeEmail))
#3 /var/www/html/site/app/Controller/NotificationsController.php(41): CakeEmail->send()
#4 [internal function]: NotificationsController->sendContact()
#5 /var/www/html/site/lib/Cake/Controller/Controller.php(485): ReflectionMethod->invokeArgs(Object(NotificationsController), Array)
#6 /var/www/html/site/lib/Cake/Routing/Dispatcher.php(186): Controller->invokeAction(Object(CakeRequest))
#7 /var/www/html/site/lib/Cake/Routing/Dispatcher.php(161): Dispatcher->_invoke(Object(NotificationsController), Object(CakeRequest), Object(CakeResponse))
#8 /var/www/html/site/app/webroot/index.php(102): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#9 {main}
2013-03-06 09:15:05 Error: Fatal Error (256): [CakeException] Unknown status code
#0 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(212): CakeResponse->statusCode(13)
#1 [internal function]: ExceptionRenderer->error400(Object(SocketException))
#2 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(175): call_user_func_array(Array, Array)
#3 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(122): ExceptionRenderer->render()
#4 [internal function]: ErrorHandler::handleException(Object(SocketException))
#5 {main} in [/var/www/html/site/lib/Cake/Error/ErrorHandler.php, line 131]
2013-03-06 09:15:05 Error: [InternalErrorException] Internal Server Error
Request URL: /notifications/sendContact
Stack Trace:
#0 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(183): ErrorHandler::handleFatalError(256, '[CakeException]...', '/var/www/html/p...', 131)
#1 [internal function]: ErrorHandler::handleError(256, '[CakeException]...', '/var/www/html/p...', 131, Array)
#2 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(131): trigger_error('[CakeException]...', 256)
#3 [internal function]: ErrorHandler::handleException(Object(SocketException))
#4 {main}
2013-03-06 09:15:05 Error: Fatal Error (256): [CakeException] Unknown status code
#0 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(212): CakeResponse->statusCode(13)
#1 [internal function]: ExceptionRenderer->error400(Object(SocketException))
#2 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(175): call_user_func_array(Array, Array)
#3 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(122): ExceptionRenderer->render()
#4 [internal function]: ErrorHandler::handleException(Object(SocketException))
#5 {main} in [/var/www/html/site/lib/Cake/Error/ErrorHandler.php, line 131]
2013-03-06 09:15:05 Error: [InternalErrorException] Internal Server Error
Request URL: /notifications/sendContact
Stack Trace:
#0 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(183): ErrorHandler::handleFatalError(256, '[CakeException]...', '/var/www/html/p...', 131)
#1 [internal function]: ErrorHandler::handleError(256, '[CakeException]...', '/var/www/html/p...', 131, Array)
#2 /var/www/html/site/lib/Cake/Core/App.php(926): call_user_func('ErrorHandler::h...', 256, '[CakeException]...', '/var/www/html/p...', 131, Array)
#3 /var/www/html/site/lib/Cake/Core/App.php(899): App::_checkFatalError()
#4 [internal function]: App::shutdown()
#5 {main}
email.php
public $gmail = array(
'transport' => 'Smtp',
'from' => array('patric.....#gmail.com' => 'Patrick Maciel'),
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'patrick......#gmail.com',
'password'=>'.......',
'client' => null,
'log' => false
);
php info (centOs)
-bash-4.1# yum info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.globo.com
* epel: mirror.globo.com
* extras: mirror.globo.com
* updates: mirror.globo.com
Installed Packages
Name : php
Arch : i686
Version : 5.4.12
Release : 1.el6.remi
Size : 8.2 M
Repo : installed
From repo : remi
Summary : PHP scripting language for creating dynamic web sites
URL : http://www.php.net/
License : PHP and Zend and BSD
Description: PHP is an HTML-embedded scripting language. PHP attempts to make it
: easy for developers to write dynamically generated web pages. PHP also
: offers built-in database integration for several commercial and
: non-commercial database management systems, so writing a
: database-enabled webpage with PHP is fairly simple. The most common
: use of PHP coding is probably as a replacement for CGI scripts.
:
: The php package contains the module which adds support for the PHP
: language to Apache HTTP Server.
Available Packages
Name : php
Arch : i386
Version : 5.3.22
Release : 1.w5
Size : 1.3 M
Repo : webtatic
Summary : PHP scripting language for creating dynamic web sites
URL : http://www.php.net/
License : PHP
Description: PHP is an HTML-embedded scripting language. PHP attempts to make it
: easy for developers to write dynamically generated web pages. PHP also
: offers built-in database integration for several commercial and
: non-commercial database management systems, so writing a
: database-enabled webpage with PHP is fairly simple. The most common
: use of PHP coding is probably as a replacement for CGI scripts.
:
: The php package contains the module which adds support for the PHP
: language to Apache HTTP Server.
-bash-4.1# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imap
intl
json
libxml
mbstring
mcrypt
memcache
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
pspell
readline
recode
Reflection
session
shmop
SimpleXML
snmp
sockets
SPL
sqlite3
standard
tidy
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
[Zend Modules]
-bash-4.1#
Apparently your PHP is not allowed to connect to the specified SMTP server. Did you properly configure your email-settings? (SMTP server, port, username, password etc).
A template for these settings is included with CakePHP in the file: app/Config/email.php.default (https://github.com/cakephp/cakephp/blob/2.2.7/app/Config/email.php.default)
You need to copy this file to app/Config/email.php and modify the settings for your environment.
After that, you'll have to specify the right configuration when sending emails
A more thorough explanation can be found in the manual:
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#configuration
update
Another option is that SELinux security-bits dissallow PHP/Apache to make network connections.
There are several security-bits, but this seems a likely candidate: httpd_can_network_connect .
You can temporarily allow PHP/Apache to make network connections using this:
setsebool httpd_can_network_connect
And make the setting 'permanent' using the -P parameter;
setsebool -P httpd_can_network_connect
For an overview of all SELibux booleans;
http://wiki.centos.org/TipsAndTricks/SelinuxBooleans
getsebool -a
Check httpd_can_network_connect
if off, set it to on
setsebool -P httpd_can_network_connect on
It works for me !!