I am trying to install phpcodesniffer in my magento module project. Below is my composer.json
{
"name": "test/myModule",
"description": "testin",
"type": "magento2-module",
"version": "1.0.0",
"require": {
"php": "^8.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*",
"magento/magento-coding-standard": "^31.0"
},
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"Test\\Module\\": ""
}
}
}
Now I can successfully run composer update/install in my folder. However when I run the command vendor/bin/phpcs --standard=Magento2 ./ I get an error like below
PHP Fatal error: Uncaught Error: Class "Magento\Framework\Component\ComponentRegistrar" not found in /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/registration.php:2
Stack trace:
#0 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/composer/autoload_real.php(55): require()
#1 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/composer/autoload_real.php(38): composerRequireabd7530303d7978f314768d362cfeb3f()
#2 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/autoload.php(25): ComposerAutoloaderInitabd7530303d7978f314768d362cfeb3f::getLoader()
#3 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/squizlabs/php_codesniffer/autoload.php(79): include('...')
#4 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/squizlabs/php_codesniffer/bin/phpcs(17): PHP_CodeSniffer\Autoload::load()
#5 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/bin/phpcs(120): include('...')
#6 {main}
thrown in /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/registration.php on line 2
How can I run the php codesniffer here?
Related
I'm trying to add authentification to my laravel app. As make:auth has been deprecated, I have tried both ui:auth and breeze.
Is it possible that I have to upgrade my composer? It came with version 1.10.1. when I installed it using the command line installation, even though the latest version is 2.5.1.
However, both
composer require laravel/breeze:1.9.2
composer require laravel/ui
produce the following error:
Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^4.1 for laravel/ui
./composer.json has been updated
PHP Fatal error: Uncaught ArgumentCountError: array_merge() does not accept unknown named parameters in /usr/share/php/Composer/DependencyResolver/DefaultPolicy.php:84
Stack trace:
#0 [internal function]: array_merge()
#1 /usr/share/php/Composer/DependencyResolver/DefaultPolicy.php(84): call_user_func_array()
#2 /usr/share/php/Composer/DependencyResolver/Solver.php(387): Composer\DependencyResolver\DefaultPolicy->selectPreferredPackages()
#3 /usr/share/php/Composer/DependencyResolver/Solver.php(740): Composer\DependencyResolver\Solver->selectAndInstall()
#4 /usr/share/php/Composer/DependencyResolver/Solver.php(231): Composer\DependencyResolver\Solver->runSat()
#5 /usr/share/php/Composer/Installer.php(489): Composer\DependencyResolver\Solver->solve()
#6 /usr/share/php/Composer/Installer.php(232): Composer\Installer->doInstall()
#7 /usr/share/php/Composer/Command/RequireCommand.php(248): Composer\Installer->run()
#8 /usr/share/php/Composer/Command/RequireCommand.php(205): Composer\Command\RequireCommand->doUpdate()
#9 /usr/share/php/Symfony/Component/Console/Command/Command.php(255): Composer\Command\RequireCommand->execute()
#10 /usr/share/php/Symfony/Component/Console/Application.php(934): Symfony\Component\Console\Command\Command->run()
#11 /usr/share/php/Symfony/Component/Console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#12 /usr/share/php/Composer/Console/Application.php(281): Symfony\Component\Console\Application->doRun()
#13 /usr/share/php/Symfony/Component/Console/Application.php(149): Composer\Console\Application->doRun()
#14 /usr/share/php/Composer/Console/Application.php(113): Symfony\Component\Console\Application->run()
#15 /usr/bin/composer(62): Composer\Console\Application->run()
#16 {main}
thrown in /usr/share/php/Composer/DependencyResolver/DefaultPolicy.php on line 84
Fatal error: Uncaught ArgumentCountError: array_merge() does not accept unknown named parameters in /usr/share/php/Composer/DependencyResolver/DefaultPolicy.php:84
Stack trace:
#0 [internal function]: array_merge()
#1 /usr/share/php/Composer/DependencyResolver/DefaultPolicy.php(84): call_user_func_array()
#2 /usr/share/php/Composer/DependencyResolver/Solver.php(387): Composer\DependencyResolver\DefaultPolicy->selectPreferredPackages()
#3 /usr/share/php/Composer/DependencyResolver/Solver.php(740): Composer\DependencyResolver\Solver->selectAndInstall()
#4 /usr/share/php/Composer/DependencyResolver/Solver.php(231): Composer\DependencyResolver\Solver->runSat()
#5 /usr/share/php/Composer/Installer.php(489): Composer\DependencyResolver\Solver->solve()
#6 /usr/share/php/Composer/Installer.php(232): Composer\Installer->doInstall()
#7 /usr/share/php/Composer/Command/RequireCommand.php(248): Composer\Installer->run()
#8 /usr/share/php/Composer/Command/RequireCommand.php(205): Composer\Command\RequireCommand->doUpdate()
#9 /usr/share/php/Symfony/Component/Console/Command/Command.php(255): Composer\Command\RequireCommand->execute()
#10 /usr/share/php/Symfony/Component/Console/Application.php(934): Symfony\Component\Console\Command\Command->run()
#11 /usr/share/php/Symfony/Component/Console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#12 /usr/share/php/Composer/Console/Application.php(281): Symfony\Component\Console\Application->doRun()
#13 /usr/share/php/Symfony/Component/Console/Application.php(149): Composer\Console\Application->doRun()
#14 /usr/share/php/Composer/Console/Application.php(113): Symfony\Component\Console\Application->run()
#15 /usr/bin/composer(62): Composer\Console\Application->run()
#16 {main}
thrown in /usr/share/php/Composer/DependencyResolver/DefaultPolicy.php on line 84
Here is my composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.0.2",
"guzzlehttp/guzzle": "^7.2",
"laravel/breeze": "1.9.2",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
"laravel/tinker": "^2.7",
"laravel/ui": "^4.1"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
},
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\Foundation\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-update-cmd": [
"#php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"#php -r "file_exists('.env') || copy('.env.example', '.env');""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
There was an issue with composer and php 8.0, as stated in this issue ticket #9097 and fixed in the newer version pull #9076
Basically, update your composer.
Try updating composer with composer self-update if you still have the same error you will need to manually update it.
If you are not familiar with the manual method, ask someone that knows to help you.
sudo apt install wget php-cli php-zip unzip
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...
Composer (version 2.0.14) successfully installed to:
/usr/local/bin/composer
Use it: php /usr/local/bin/composer
I'm trying to serve (php artisan serve) a Laravel application but for some reason I'm getting this fatal error:
PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1338
Stack trace:
#1 C:\Program Files\Ampps\www\emotions\vendor\composer\ClassLoader.php(444): include('...')
#2 C:\Program Files\Ampps\www\emotions\vendor\composer\ClassLoader.php(322): Composer\Autoload\includeFile()
#3 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Support\helpers.php(110): Composer\Autoload\ClassLoader->loadClass()
#4 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): collect()
#5 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config()
#6 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases()
#7 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(230): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap()
#8 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith()
#9 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap()
#10 C:\Program Files\Ampps\www\emotions\artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#11 {main}
Does anyone know what is going on? I've tried upgrading the PHP version the project is using in the composer.json (project is using ^7.2.5 and I'm using 8.1.2) but nothing has worked.
Update composer.json on your laravel project.
like this
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.2|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.40",
"laravel/tinker": "^2.5"
},
I got the error regarding facade even though I followed the laravel upgrade guide
PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Support\Faca
des\Facade.php:258
Stack trace:
#0 D:\Git_Undiksha\legalisir-ijasah-online\app\Exceptions\Handler.php(39): Illuminate\Support\Facades\Facade::__callStatic('error', Array)
#1 D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(366): App\Exceptions\Handler->report(Object(Error))
#2 D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(131): Illuminate\Foundation\Console\Kernel->reportException
(Object(Error))
#3 D:\Git_Undiksha\legalisir-ijasah-online\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Compo
nent\Console\Output\ConsoleOutput))
#4 {main}
thrown in D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 258
Fatal error: Uncaught RuntimeException: A facade root has not been set. in D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Support\Facades\F
acade.php:258
Stack trace:
#0 D:\Git_Undiksha\legalisir-ijasah-online\app\Exceptions\Handler.php(39): Illuminate\Support\Facades\Facade::__callStatic('error', Array)
#1 D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(366): App\Exceptions\Handler->report(Object(Error))
#2 D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(131): Illuminate\Foundation\Console\Kernel->reportException
(Object(Error))
#3 D:\Git_Undiksha\legalisir-ijasah-online\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Compo
nent\Console\Output\ConsoleOutput))
#4 {main}
thrown in D:\Git_Undiksha\legalisir-ijasah-online\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 258
Facade.php:258
public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
if (! $instance) {
throw new RuntimeException('A facade root has not been set.');
}
return $instance->$method(...$args);
}
Here is my composer.json:
"require": {
"php": ">=7.2.5",
"laravel/framework": "^7.0",
"nunomaduro/collision": "^4.1",
"laravel/tinker": "^2.0",
"facade/ignition": "^2.0"
},
"require-dev": {
"composer/composer": "^1.10",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "^9.1"
},
I did change the Handler.php Exception to Throwable, session.php secure env from false to null, and set any handle() command return to integer.
How do I solve the facade error and what should I do?
After making a new working Laravel version 7 project, copy the app and config folders to the new one (for testing purpose), renaming a file and then testing with php artisan --version every changes I made (rename each no-numbered files to (1) and (2) files to no-numbered), finally I found out what is the problem: config/excel.php
in excel.php I commented autosize-method and it works!
// 'autosize-method' => PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX,
I have this error when I try to run a console command with Silex.
PHP Error: Class 'Testing\Command\TestingCommand' not found in /var/www/testCmd/app/console on line 9
PHP Stack trace:
PHP 1. {main}() /var/www/testCmd/app/console:0
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TestingCommand" from namespace "Testing\Command".
Did you forget a "use" statement for another namespace? in /var/www/testCmd/app/console:9
Stack trace:
#0 {main}
thrown in /var/www/testCmd/app/console on line 9
I have app/console.php and app/bootstrap.php files. The console is loading the bootstrap and in the console file I have some thing like:
#!/usr/bin/env php
<?php
set_time_limit(0);
$app = require_once __DIR__ . '/bootstrap.php';
$application = $app['console'];
$app['console']->add(new \Testing\Command\TestingCommand());
$application->run();
composer file
{
"name": "testing/Command",
"require": {
"knplabs/console-service-provider": "^2.0",
"silex/silex": "^2.0",
"symfony/monolog-bridge": "^3.1",
"doctrine/common": "^2.6",
"doctrine/dbal": "^2.5"
},
"autoload": {
"psr-4": {
"\\": "src/"
}
}
}
The command is located in src/Command/TestingCommand.php
I am super new to Silex and I don't know what can cause the issue. Thank you
Autoloader can't load command class. According to autoload section of composer.json and class name file with this class should be located in src/Testing/Command/TestingCommand.php. So you can move this file in this location or set another search directory in composer.json:
"autoload": {
"psr-4": {
"Testing\\Command\\": "src/Command/"
"\\": "src/"
}
}
after changing composer.json run composer dump-autoload
https://getcomposer.org/doc/01-basic-usage.md#autoloading
After doing composer update my project starts to show this error in everywhere in my production environment. But in local is working perfectly.
Fatal error: Uncaught exception 'ReflectionException' with message 'Class log does not exist' in
.../src/Illuminate/Container/Container.php:736 Stack trace: #0
.../src/Illuminate/Container/Container.php(736): ReflectionClass->__construct('log') #1
.../src/Illuminate/Container/Container.php(626): Illuminate\Container\Container->build('log', Array) #2
.../src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('log', Array) #3
.../src/Illuminate/Container/Container.php(837): Illuminate\Foundation\Application->make('Psr\\Log\\LoggerI...') #4
.../src/Illuminate/Container/Container.php(800): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter)) #5
.../src/Illuminate/Container/Container.php(771): Illuminate\Cont in
.../src/Illuminate/Container/Container.php on line 736
My local environment is OSX 10.10.5 and my production environment is Linux.
I made composer update again but don't fix the error.
My composer.json is look like this:
...
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"folklore/image": "0.2.*",
"illuminate/html": "5.*",
"cartalyst/sentry": "dev-feature/laravel-5"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"laracasts/generators": "~1.1",
"php-console/php-console": "~3.0",
"php-console/laravel-service-provider": "~5.0"
},
...
Thanks guys!
I found the problem.
I removed the packages of my composer.json and works.
"php-console/php-console": "~3.0",
"php-console/laravel-service-provider": "~5.0"
I think that the server does not support the packages because is necessary a .bat file for the packages work.
Most of the times, this error fixing is very simple. Just run
composer dump-autoload
and without any doubt, your error will be fixed.