The following gives this error 3 times:

Concat operator must be surrounded by a single space
      throw new \Exception('$visibility must be one of (' .
      BLOCK_VISIBILITY_NOTLISTED . ', ' .
      BLOCK_VISIBILITY_LISTED . ', ' .
      BLOCK_VISIBILITY_PHP . '), got(' . $visibility . ')'
      );

Placing them all on one very long line prevents the Coder error report, but is far less readable:

      throw new \Exception('$visibility must be one of (' . BLOCK_VISIBILITY_NOTLISTED . ', ' . BLOCK_VISIBILITY_LISTED . ', ' . BLOCK_VISIBILITY_PHP . '), got(' . $visibility . ')'
      );

May I suggest that having a newline after a concat operator plays much the same role as a space, makes in many cases for more readable code, and should be permitted, as long as that concat operator as a space before it as shown.

(I appreciate that some circumstances like this are better handled with placeholders.)

Comments

klausi’s picture

Category: Feature request » Bug report
Status: Active » Postponed (maintainer needs more info)

This works as designed for me and does not throw the error. Did you run composer install to get the latest dependencies for 8.x-2.x-dev?

webel’s picture

Category: Bug report » Support request
Status: Postponed (maintainer needs more info) » Active

Thanks for prompt feedback.

@klausi wrote:

> Did you run composer install to get the latest dependencies for 8.x-2.x-dev?

I have recent 8.x-2.x-dev but I have not been using composer.

I have been using PEAR to install PHP_CodeSniffer:

$ phpcs --version
PHP_CodeSniffer version 2.3.0 (stable) by Squiz (http://www.squiz.net)
$ which phpcs
/usr/local/bin/phpcs

I have been using Drush to install Coder in accordance with https://www.drupal.org/node/1419988#coder-drush
(but targeting coder-8.x-2.x-dev):

$ drush dl coder-8.x-2.x-dev --destination=$HOME/.drush
$ drush cc drush

My .drush/coder and drush/coder_sniffer reflect the update time a couple of days ago:

5 Apr 13:27 coder


5 Apr 13:27 coder_sniffer


~/.drush/coder/coder_sniffer/
5 Apr 13:27 Drupal

I've tried running using drush drupalcs, phpcs --standard=Drupal. and using the PHPCSMD plugin with phpcs /usr/local/PEAR/PHP/CodeSniffer/Standards/ linked to the ..drush/coder/coder_sniffer/Drupal standard

Q: Is there anything else I have to do to ensure all dependencies are updated ?

webel’s picture

Priority: Normal » Major

@klausi I appreciate your recent help with many Coder-related issues.

I am bumping this support request issue to MAJOR status to get your assistance with this issue with priority because:

1. I want to make sure that my issue reports elsewhere are using the correct set for Coder 8.x.-2.x-dev and dependencies, and if you state you are not hitting this problem then I need to be sure that my setup is correct.

2. I have commenced applying target to a new contributed module sandbox project today and I am hitting this error report a huge number of times, in part because that module uses relatively verbose description text for some form fields (which may be better handled some other way), like this:

  // Checkbox field for whether to show the banners block.
  $form[Common::KEY_FIELDSET_BLOCK][Common::VAR_ADMIN_DO_SHOW_BANNER_BLOCK] = array(
    '#type' => 'checkbox',
    '#title' => t('Show the banners block ?'),
    '#default_value' => variable_get(Common::VAR_ADMIN_DO_SHOW_BANNER_BLOCK, FALSE),
    '#description' => t('If TRUE, the banners block will be shown for all flaggable node content.') . ' ' .
    t('You can also choose below whether to show a banner for flagged and/or NOT flagged content per-Flag type.') . ' ' .
    t('You may NOT choose to show both the banners block and the banners decorator at once !') . ' ' .
    t('Remember to also allocate the banners block to a region (usually to Content) under:') . ' ' .
    l(t('Blocks'), '/admin/structure/blocks'),
  );

The sniff that is causing this seems to be:

31 Mar 18:18  /usr/local/PEAR/PHP/CodeSniffer/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php

This date 31 Mar 18:18 corresponds with:

31 Mar 18:18 /usr/local/bin/phpcs

From:

PHP_CodeSniffer   2.3.0   stable
# pear upgrade -a PHP_CodeSniffer
Nothing to upgrade

Without switching to composer (yet) how can I ensure the dependencies are correct ? Composer my be preferable, but it should be possible and clear to maintain Coder + CodeSniffer without it.

klausi’s picture

You need PHPCS at least revision 081f49aa967e2cd7c579442ffa05ef0193c6018a as specified as dependency in composer.json. That version is not released yet, we are waiting for 2.4.0 or 2.3.1 to be released.

If you use the dev version you should either use a git clone of PHPCS or use composer to fetch the required version.

webel’s picture

@klausi wrote:

You need PHPCS at least revision 081f49aa967e2cd7c579442ffa05ef0193c6018a as specified as dependency in composer.json. That version is not released yet, we are waiting for 2.4.0 or 2.3.1 to be released.

If you use the dev version you should either use a git clone of PHPCS or use composer to fetch the required version.

@kausi I have managed to get this working but I found it very tricky.

I could not figure out how to edit ~/.composer/composer.json or how to use composer on the command line to get Composer to download the correct 'drupal/coder' AND the correct 'squizlabs/php_codesniffer' (see below, but I don't expect you to untangle that problem).

In case this helps others, the following worked for me.

I uninstalled my PEAR managed version of PHP_CodeSniffer:

pear uninstall PHP_CodeSniffer
uninstall ok: channel://pear.php.net/PHP_CodeSniffer-2.3.0

I had to mv this away still by hand:

/usr/local/PEAR/PHP/CodeSniffer

I deleted ~/.composer/composer.json and ~/.composer/composer.lock.

I installed only php_codesniffer using composer:

# composer global require "squizlabs/php_codesniffer=dev-master#081f49aa967e2cd7c579442ffa05ef0193c6018a"
Changed current directory to .../.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing squizlabs/php_codesniffer (2.3.0)
  - Installing squizlabs/php_codesniffer (dev-master 081f49a)
    Cloning 081f49aa967e2cd7c579442ffa05ef0193c6018a 
Writing lock file
Generating autoload files

The resulting ~/.composer/composer.json is:

{
    "require": {
        "squizlabs/php_codesniffer": "dev-master#081f49aa967e2cd7c579442ffa05ef0193c6018a"
    }
}

I linked to the executables ('PEAR uninstall' having deleted the former ones):

# sudo ln -s ~/.composer/vendor/bin/phpcs /usr/local/bin
# sudo ln -s ~/.composer/vendor/bin/phpcbf /usr/local/bin

# phpcs --version
PHP_CodeSniffer version 2.3.1 (stable) by Squiz (<a href="http://w

After dozens of failed experiments with Composer for drupal/coder trying to get the 8.x-2.x-dev version to install (without tripping on the php_codesniffer dependency) I gave up and just linked my standards from my latest drush install.

$ cd ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards
$ ln -s ~/.drush/coder/coder_sniffer/Drupal .

This was then caught ok by both 'drush drupalcs" and by the PHPCSMD plugin for NetBeans8.0.

And the incorrect error report 'Permit concat operator at end of line' was indeed gone for the examples I gave above.

Some things that did not work for me

This is a bit off topic for this issue report but it may help somebody else.

I am relatively new to Composer. Despite reading the Composer docs I could not figure out how to pull drupal/coder 8.x-2.x-dev and the above version of squizlabs/php_codesniffer.

One challenge I had was figuring out how to specify Coder 8.x-2.x for composer on the command line with a global require. Eventually I found under #2002184: Create composer.json to provide Drupal code sniffer rules as external library:

due to the non-semantic way in which Drupal modules
are versioned, you must require a dev branch.

So for instance, you'd need something like this:

"require": {
"drupalproject/coder": "dev-7.x-2.x"
}

This also means that your root project must have a minimum-stability of dev.

"minimum-stability": "dev"

So I tried 'dev-8.x-2.x':

$ composer global require drupal/coder:dev-8.x-2.x
Changed current directory to ~/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
 
  Problem 1
    - Installation request for drupal/coder dev-8.x-2.x -> satisfiable by drupal/coder[dev-8.x-2.x].
    - drupal/coder dev-8.x-2.x requires squizlabs/php_codesniffer dev-master#081f49aa967e2cd7c579442ffa05ef0193c6018a -> no matching package found.
 
Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion
 
Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
 
Installation failed, reverting ./composer.json to its original content.

I played with:

 "minimum-stability": "dev"

didn't seem to help.

Even if I installed the default version:

$ composer global require drupal/coder

This didn't seem to do anything useful:

phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

And when I linked "by hand" to the standards under:

 ~/.composer/vendor/drupal/coder/coder_sniffer 

I could then tell they were out of date, hence I removed that link and linked to the latest Drush-installed version 8.x-2.x-dev.

Suggestion: please include instructions on installing specific versions

Could you please, time-permitting, include instructions at https://www.drupal.org/node/1419988#coder-composer on how to global install specific Coder versions such as 8.x-2.x-dev and a specific Code Sniffer match using composer on the command line, and/or how the ~/.composer/composer.json should look to a achieve this.

I can see from a downloaded Coder 8.x-2.x-dev from 2015-Apr-06 the dependency in its composer.json file:

    "require": {
        "php": ">=5.2.0",
        "squizlabs/php_codesniffer": "dev-master#081f49aa967e2cd7c579442ffa05ef0193c6018a"
    },

But my global composer install into ~/.composer is falling over (with a dozen variations of problems like above that I'll omit).

webel’s picture

Priority: Major » Minor

If you can provide help on correct command-line use of composer or composer.json setup then please do, otherwise please close as "fixed".

klausi’s picture

Status: Active » Fixed

New release is out, now pointing to a stable PHPCS version again, so this should all be easier again :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.