Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist - drupal

Just installed php_codesniffer and coder:
composer global require "squizlabs/php_codesniffer=*"
composer global require drupal/coder
After installation, run phpcs -i and the result is as follows:
The installed coding standards are MySource, PEAR, Zend, PSR2, PSR1, Squiz, PSR12, PHPCompatibility, Drupal and DrupalPractice
But when I use git commit, I get an error:
ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist
My php version is 7.4.
Where am I going wrong?

Excuting an order:
phpcs --config-set installed_paths /homeriverz/.config/composer/vendor/phpcompatibility/php-compatibility,/homeriverz/.config/composer/vendor/drupal/coder/coder_sniffer,/homeriverz/.config/composer/vendor/slevomat /coding-standard
If not, reinstall php_codesniffer and drupal/coder.

Related

Upgraded Drush 8 to 9 Site Alias Not Working

I moved from using Docksal to Acquia ADS (Lando) which automatically upgraded my Drush from 8 to 9. My local site works fine but I can't get Drush 9 to "see" my Drupal 8 site. The aliases seem to have been created and added to the drush/sites folder and running drush site:alias does show them. However running drush status shows my Drupal root as /app. My Drupal root is /app/docroot. My alias files do have this as their root (for local). I'm not sure why Drush doesn't use the alias files it knows about. I've tried:
drush #self(or #local) list and I get some commands and this statement at the end:
[NOTE] Drupal root not found. Pass --root or a #siteAlias in order to see Drupal-specific commands.
Doing drush #local(or #self) cr returns:
In BootstrapHook.php line 32: Bootstrap failed. Run your command
with -vvv for more information.
With -vvv:
Exception trace: at
/app/vendor/drush/drush/src/Boot/BootstrapHook.php:32
Drush\Boot\BootstrapHook->initialize() at
/app/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:34
Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook()
at
/app/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:27
Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize()
at
/app/vendor/consolidation/annotated-command/src/CommandProcessor.php:145
Consolidation\AnnotatedCommand\CommandProcessor->initializeHook() at
/app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:289
Consolidation\AnnotatedCommand\AnnotatedCommand->initialize() at
/app/vendor/symfony/console/Command/Command.php:221
Symfony\Component\Console\Command\Command->run() at
/app/vendor/symfony/console/Application.php:1005
Symfony\Component\Console\Application->doRunCommand() at
/app/vendor/symfony/console/Application.php:255
Symfony\Component\Console\Application->doRun() at
/app/vendor/symfony/console/Application.php:148
Symfony\Component\Console\Application->run() at
/app/vendor/drush/drush/src/Runtime/Runtime.php:118
Drush\Runtime\Runtime->doRun() at
/app/vendor/drush/drush/src/Runtime/Runtime.php:49
Drush\Runtime\Runtime->run() at /app/vendor/drush/drush/drush.php:72
require() at /app/vendor/drush/drush/drush:4
drush status:
PHP binary : /usr/local/bin/php
PHP config :
PHP OS : Linux
Drush script : /app/vendor/drush/drush/drush
Drush version : 10.2.2 <-- Had 9.0.0 but currently trying 10, same issue
Drush temp : /tmp
Drush configs : /root/.drush/drush.yml
/app/vendor/drush/drush/drush.yml
/app/drush/drush.yml
Drupal root : /app
self.site.yml:
local:
root: /app/docroot
uri: example.lndo.site
Can someone please point me in the right direction?
Figured it out. No matter how many ways you try to tell Drush where to look to find your Drupal root, none of it will matter until you edit your composer.json file. Turns out the key to making Drush 9+ work is changing the name in composer.
My composer.json file name went from:
"name": "drupal/drupal",
to:
"name": "drupal-composer/drupal-project",
I don't think this feature was documented anywhere so I'm posting it here in response to my own question in case this helps anyone else.
I realize that this is an older question, however with Drupal 8 recently reaching end of life, and the high probability of many people (like myself) scrambling to upgrade now that clients have realized the risks of using EOL software, I want to take a moment to explain why #r00t's answer works.
r00t is correct that changing the "name" value in composer.json fixed the issue, however, the value that is set is not limited to drupal-composer/drupal-project. This seems to stem from the package webflo/drupal-finder and the way it works.
webflow/drupal-finder is a requirement of drush/drush, so it's going to be included even if you haven't added it manually. It's also a requirement of a couple of others that you may or may not have installed, like palantirnet/drupal-rector (which as a side note, is really helpful for this upgrade).
Within the code for drupal-finder is a method that looks for the install path of Drupal core based on a few items within your composer.json file.
Here is the code from DrupalFinder::isValidRoot()
foreach ($json['extra']['installer-paths'] as $install_path => $items) {
if (in_array('type:drupal-core', $items) ||
in_array('drupal/core', $items) ||
in_array('drupal/drupal', $items)) {
$this->composerRoot = $path;
// #todo: Remove this magic and detect the major version instead.
if (($install_path == 'core') || ((isset($json['name'])) && ($json['name'] == 'drupal/drupal'))) {
$install_path = '';
} elseif (substr($install_path, -5) == '/core') {
$install_path = substr($install_path, 0, -5);
}
....
Which is telling drupal-finder that if the "name" value is drupal/drupal then the install path of the site is at the base of the project, however if it is not drupal/drupal then use a value from extra.installer-paths to find the site install.
I'm still not aware if this is documented anywhere on either webflo/drupal-finder or in drush/drush, but understanding why it was an issue helped me out tremendously.
TL;DR:
If your site's docroot lives next to your vendor folder, change the name in composer.json to anything that isn't drupal/drupal. If your vendor folder lives inside your docroot, drupal/drupal will work for you.

class PHPUnit\Framework\ExpectationFailedException not found

when I try to run a failed test with this command :
./vendor/bin/phpunit
I get this Fatal Error :
PHPUnit 5.7.20 by Sebastian Bergmann and contributors.
PHP Fatal error: Class 'PHPUnit\Framework\ExpectationFailedException'
not found in /var/www/zend/vendor/zendframework/zend-
test/src/PHPUnit/Controller/AbstractControllerTestCase.php on line 444
Your version of phpunit is probably too old for your version of Zend. The class PHPUnit\Framework\ExpectationFailedException have been renamed in PhpUnit 6.X from PHPUnit_Framework_ExpectationFailedException to ExpectationFailedException
Please check your PhpUnit version: phpunit --version, it should be 6.X. Update it to the last version to avoid this error.
This is "fixed" by a script in Zend\Test called phpunit-class-aliases.php but it's not configured properly IMHO since it's in the autoload-dev section (meaning it doesn't propagate out to other projects.)
So, in your project composer.json, do something like this:
"autoload-dev": {
"files": [
"vendor/zendframework/zend-test/autoload/phpunit-class-aliases.php"
]
},
Then composer install
N.B. Zend\Test has a pull request that fixes this very thing, but they're saying it's PHPUnit's fault (Shame on you PHPUnit 4 for... idunno... having the wrong class name according to Zend\Test) So, I've done it instead: composer require illchuk/phpunit-class-aliases
This is a configuration flaw in zend-test. It consumes classes from Phpunit 6 but per it's Composer requirements, Phpunit before that version are OK to require:
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0",
Most likely as your system because of the PHP version does not satisfy the requirements of Phpunit 6, the next lower version was installed.
As the code in the base test case (https://github.com/zendframework/zend-test/blob/master/src/PHPUnit/Controller/AbstractControllerTestCase.php#L444) makes use of Phpunit 6 classes, I strongly assume that when the configuration flaw is made aware to the Zend-Test project, you won't be even able to install on your system any longer.
Therefore upgrade to a recent PHP version and then run
composer update
If you're stuk with the PHP version, downgrade zend-test to a version that supports an older Phpunit version. I don't know that project well, so it's just a suggestion, I don't know if such a version exists or can't even recommend one.
I filed a report, perhaps using that one class was an oversight or there is a less hard way to resolve the dependency: https://github.com/zendframework/zend-test/issues/50

Symfony2 Composer install calls wrong php installation/version internally

I'm trying to set up Symfony 2.5 via Composer.
First I am calling:
php5.3.8-cli /kunden/81425/composer.phar create-project symfony/framework-standard-edition hhcadm/ "2.5.*"
This works until at some point it is internally not calling php5.3.8-cli anymore but somehow uses php. The problem is that php is version 4.4.9 and this causes following effect:
Nothing to install or update
Generating autoload files
Updating the "app/config/parameters.yml" file
X-Powered-By: PHP/4.4.9
Content-type: text/html
<br />
<b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in <b>/kunden/81425/hhcadm/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php</b> on line <b>13</b><br />
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap handling the post-install-cmd event terminated with an exception
[RuntimeException]
An error occurred when generating the bootstrap file.
The error makes sense as 4.4.9 is too old. How can I tell Composer/Symfony installer which php installation to use during the install routine?
Same happens for me when I call:
php5.3.8-cli /kunden/81425/composer.phar install
I am pretty shure there must be a config / param for that but I can't find it for hours now.
Thank you very much.
'php' must be the PHP5 executable.
The only solution i see is to modify the PATH, launch the composer command (and eventually restore the old path)
For example :
OLDPATH=$PATH
PATH=/usr/local/php5/bin:$PATH
php /kunden/81425/composer.phar install
PATH=$OLDPATH
To help you, you can also create a small script 'composer.sh' :
#!/bin/sh
OLDPATH=$PATH
PATH=/usr/local/php5/bin:$PATH
php /kunden/81425/composer.phar $*
PATH=$OLDPATH
And you call 'composer.sh install'
Edit : if all php binaries are in the same, you can create symbolic links
For example :
mkdir /usr/local/bin/php5
ln -s /usr/local/bin/php53-cli /usr/local/bin/php5/php
And so PATH=$PATH:/usr/local/bin/php5:$PATH
Edit: If you are not allowed to create /usr/local/bin/php5 then just use any other folder like:
#!/bin/sh
OLDPATH=$PATH
PATH=/kunden/81425/php5:$PATH
php /kunden/81425/composer.phar $*
PATH=$OLDPATH

FatalErrorException: Error: Class 'ResourceBundle' not found

I installed and configured FOSUserBundle, SonataAdminBundle, SonataUserBundle, SonataMediaBundle correctly as written in here http://tech.dupeu.pl/2013/07/symfony-2-3-sonataadminbundle-sonatamediabundle-sonatauserbundle-and-fosuserbundle-a-good-project-base/ and with some research it's fine and I already can create a user, a superadmin etc..
Also Media ans Groups features works correctly ! I have a problem when tryin to add a user in the Admin Dashbord, I donnow exactly what it is about .. I searched on forums and on stackoverflow and it seems that it has a relation with SonataIntlBundle so I reinstalled it and I activated intl extension in my WampServer (Windows 8) but it's not working anymore ..
This is the error ( FatalErrorException: Error: Class 'ResourceBundle' not found in C:\wamp\www\project\vendor\symfony\symfony\src\Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader.php line 32 )
Solved
I fixed the problem by installing symfony/intl with composer : I added this "symfony/intl": "2.6.*#dev" to requiere section then I lunched the composer update command and now it's working !
You can check this link http://symfony.com/doc/current/components/intl.html for more informations!
ResourceBundle is a dependency of intl extension, so your intl or ICU version are wrong. Search for the right version (Thread Safe or not, 32bit or 64bit).
On WAMP is hard to found the right version. If I remember, when I had this issue, I had to downgrade my WAMP version.

How to install mmoreramerino/GearmanBundle with Symfony 2.1.x?

I am pretty new to Symfony 2 and brand new to Gearman.
I am looking for a bundle to integrate Symfony 2 with Gearman.
mmoreramerino's bundle seems to be the most popular bundle according to packagist. Unfortunately something seems to be broken, the autoloader does not find the bundle.
Fatal error: Class 'Mmoreramerino\GearmanBundle\MmoreramerinoGearmanBundle' not found in ...
I tried switching to "dev-development" as I got from the issues that it was fixed in this branch, but it did not work for me as well.
Question: How can I install this bundle using Symfony 2.1.x?
Question 2: Are there any working & documented alternatives?
Edit In case someone else comes across this question: Here is how I got it up and running!
Install gearman, libgearman, the PECL extension for PHP (use recent versions!)
check that gearman shows up in phpinfo() (both cli and webserver version)
start gearmand in terminal 1 using "gearmand --verbose INFO" (you will see workers & clients connect to gearman - or not ;-))
start in terminal 2 reverse_worker.php from the gearman php extension example directory
start in terminal 3 reverse_client.php from the gearman php extension example directory
If this is working, you are ready for Symfony: install mmoreramerino/GearmanBundle using "dev-development"
copy dev.base.yml from the bundle to app/config/gearman/dev.yml
Now add TestWorker.php to your bundle as outlined in the documentation
enable the testWorker by using the console script "php app/console gearman:job:execute MmoreramerinoGearmanBundleWorkerstestWorker~test"
now you are able to send jobs to the listening testWorker in a Symfony controller (or somewhere else in Symfony). I had to specify the server though I am using the default host/port.
$gearman = $this->get('gearman');
$gearman->setServer('127.0.0.1',4730);
$gearman->doNormalJob('MmoreramerinoGearmanBundleWorkerstestWorker~test');
To install the bundle, you need to add the following line to composer.json
"Mmoreramerino/GearmanBundle": "dev-development"
and run composer update;
Then register it in app/AppKernel.php (it seems you have already done this)
new Mmoreramerino\GearmanBundle\MmoreramerinoGearmanBundle(),

Resources