Problem with PHP_CodeSniffer and SVN pre-commit hook - php

I've recently downloaded the latest version of CodeSniffer (1.3.RC0). I prefer this version and not the stable one (1.2.2) because I want the "severity" feature.
I've modified an existing Drupal standard package to be compatible with this version of CodeSniffer and stablish my own severity policy. When I run the phpcs from command-line, I've no problems at all. It sniffs the code correctly, filters severity and works fine.
The problem comes when I try to automate the sniffs with the subversion pre-commit hook. It seems that the phpcs-svn-pre-commit script coming with this release is not working at all.
I've followed the guide in http://pear.php.net/manual/en/package.php.php-codesniffer.svn-pre-commit.php step-by-step, but when I commit a file with coding standard errors (detected by command-line execution of phpcs and my Drupal standard package), subversion simply lets the file pass and commits the changes.
Has anybody been in the same problem?
Thanks in advance.
EDITED: execution examples.
$ phpcs --standard=Drupal --severity=4 ak_gourmet.module
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/IcePHP.so' - /usr/lib/php5/20090626/IcePHP.so: cannot open shared object file: No such file or directory in Unknown on line 0
FILE: ...ce/trunk/httpdocs/sites/all/modules/custom/ak_gourmet/ak_gourmet.module
--------------------------------------------------------------------------------
FOUND 21 ERROR(S) AFFECTING 27 LINE(S)
--------------------------------------------------------------------------------
17 | ERROR | Concat operator must be surrounded by spaces. Found "...
| | '<p>'. "; expected "... . "
17 | ERROR | Concat operator must be surrounded by spaces. Found "...
| | .'</p>';..."; expected "... .;..."
40 | WARNING | A comma should follow the last multiline array item. Found:
| | MENU_NORMAL_ITEM
53 | WARNING | A comma should follow the last multiline array item. Found:
...
Line added in subversion pre-commit hook (it is being executed):
# execute code sniffer with drupal standards
/usr/bin/scripts/phpcs-svn-pre-commit --standard=Drupal --severity=4 "$REPOS" -t "$TXN" >&2 || exit 1
Committing the incorrect file:
$ svn commit -m "Testing svn hook-precommit" ak_gourmet.module
Enviando ak_gourmet.module
Transmitiendo contenido de archivos .
Commit de la revisión 5814.

Related

VScode PHPCS Extension Error: Referenced Sniff "WordPress-Core" does not exist

I want to add PHP CodeSniffer to VScode.
Within VScode I am getting the error 'phpcs: Referenced sniff "WordPress-Core" does not exist'
However when I run the following command in the terminal:
phpcs --standard="WordPress-Core" dropdowns.php
PHP CodeSniffer works as expected with the following terminal output:
--------------------------------------------------------------------------------
FOUND 34 ERRORS AND 17 WARNINGS AFFECTING 51 LINES
--------------------------------------------------------------------------------
15 | WARNING | [x] Array double arrow not aligned correctly; expected 10
| | space(s) between "'id'" and double arrow, but found 1.
17 | WARNING | [x] Array double arrow not aligned correctly; expected 4
| | space(s) between "'taxonomy'" and double arrow, but found
| | 1.
18 | WARNING | [x] Array double arrow not aligned correctly; expected 5
| | space(s) between "'orderby'" and double arrow, but found
| | 1.
34 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 10 spaces but found 1 space
35 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 7 spaces but found 1 space
36 | ERROR | [x] Short array syntax is not allowed
44 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 2 spaces but found 1 space
84 | WARNING | [x] Equals sign not aligned with surrounding assignments;
| | expected 2 spaces but found 1 space
My settings.json file looks like this:
{
"workbench.colorTheme": "Default Light+",
"window.zoomLevel": 0,
"phpcs.standard": "WordPress",
"phpcs.executablePath": "/Users/michelle/.composer/vendor/bin/phpcs",
"phpcs.enable": true,
"phpcs.showWarnings": true,
"phpcs.showSources": true,
}
My phpcs.ruleset.xml looks like this:
<?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards">
<description>My Project's Coding Standards</description>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Docs"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Extra"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Core"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPressVIPMinimum"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-VIP-Go"/>
</ruleset>
I solved this error by updating the rule references in this file:
~/.composer/vendor/wp-coding-standards/wpcs/WordPressto also be absolute paths. Final ruleset.xml for WordPress coding standards now looks like this:
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WordPress" namespace="WordPressCS\WordPress" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<description>WordPress Coding Standards</description>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Core"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Docs"/>
<rule ref="~/.composer/vendor/wp-coding-standards/wpcs/WordPress-Extra">
<!-- Prevent duplicate messages + deprecation notice from deprecated sniff. -->
<exclude name="WordPress.WP.TimezoneChange.timezone_change_date_default_timezone_set"/>
<exclude name="WordPress.WP.TimezoneChange.DeprecatedSniff"/>
</rule>
</ruleset>
There is a good chance that you're using multiple versions of phpcs.
Try, in a shell:
which phpcs
If you get something like /usr/bin/phpcs, you have the package installed with your system's package manager. Either manage it using the package manager -- install WordPress-Core with apt or brew or whatever you're using -- or remove it (then try again).
If you don't get a result, try to install PHPCS globally using Composer. Make sure ~/.config/composer/vendor/bin is in your PATH.
At this point, you know the path of the executable that you want to use, and you know where it is. Now:
phpcs -i
That will give you a list of installed standards. Mine says: MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, PHPCompatibility, PHPCompatibilityParagonieRandomCompat, PHPCompatibilityParagonieSodiumCompat, PHPCompatibilityWP, WordPress-Core, WordPress-Docs, WordPress-Extra and WordPress.
You know where your executable is and you know how to modify it (either Composer with global, or apt, or brew, or whatever). Keep installing until you get the right thing.
If you're using a PHPCS extension in VS Code and you haven't specified a full path to the executable, it may be checking in your project path. Given how easy it is to set up Composer with lots of stuff, it may be finding another copy of the executable.
Set the extension to point to the correct executable. Now it should be able to find all the standards you need.
Also make sure that you're not running multiple VS Code extensions. If you're anything like me, when you move to a new install, you go and install 50 extensions of all the things you think you may need one day. Some meta-extensions come with PHPCS, commonly bundled with a formatter, or, "everything you need to code in VS Code in PHP." Make sure that either:
only one extension is linting, or,
all linters are pointing to the correct phpcs executable.
This should fix this issue permanently.
you need to make all installed coding standards available to phpcs:
phpcs --config-set installed_paths full-wpcs-path\WordPress,full-wpcs-path\WordPress-Core,full-wpcs-path\WordPress-Docs,full-wpcs-path\WordPress-Extra
see phpcs.standard in:
https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs

Adding php-curl in a Yocto build

I've been building a custom image using Yocto and wpewebkit to use within docker. I need to run a local web server with php, which I have accomplished no problem. I need to use curl within my project and I have apache2, php, modphp, and curl installed. All I need is php-curl but I cannot find how to install this. Does anyone know how or if I can do this? I've put in all my efforts on googling multiple phrases but I only find how to install php-curl using apt-get or yum, or I get links to the meta-* directories which I have access to within my build files anyways.
If it helps at all, this custom image was based on the image provided from the following project on GitHub: https://github.com/resin-io-playground/resin-wpe/tree/master/base-image . I already spoke to the developer and their knowledge of PHP is limited.
EDIT #1: Progress so far, had to update the curl.bb file to properly include libcurl-dev, and then worked with #pmod's suggestion to incorporate curl into the php build. Everything seemed to run okay until I received the following error:
| ../php-7.1.9/configure: line 386: test: please: integer expression expected
| configure: error: reinstall
| ../php-7.1.9/configure: line 275: return: please: numeric argument required
| ../php-7.1.9/configure: line 285: exit: please: numeric argument required
| NOTE: The following config.log files may provide further information.
| NOTE: /base-image/build/tmp-glibc/work/x86_64-linux/php-native/7.1.9-r0/build/config.log
| ERROR: configure failed
| WARNING: /base-image/build/tmp-glibc/work/x86_64-linux/php-native/7.1.9-r0/temp/run.do_configure.29590:1 exit 1 from 'exit 1'
| ERROR: Function failed: do_configure (log file is located at /base-image/build/tmp-glibc/work/x86_64-linux/php-native/7.1.9-r0/temp/log.do_configure.29590)
ERROR: Task (virtual:native:/base-image/build/../meta-openembedded/meta-oe/recipes-devtools/php/php_7.1.9.bb:do_configure) failed with exit code '1'
Edit #2: I've gone ahead and added everything I was missing. I'm getting the same error above, where the function do_configure during the php build is failing. I'm posting below what I ensured I have in my curl.bb file (I had to add this), what I have in my php.inc file, and the curl files located staging directory.
curl.bb:
PACKAGES =+ "lib${BPN} lib${BPN}-native lib${BPN}-dev lib${BPN}-dev-native"
FILES_lib${BPN} = "${libdir}/lib*.so.*"
FILES_lib${BPN}-dev = "${includedir} \
${libdir}/lib*.so \
${libdir}/lib*.a \
${libdir}/lib*.la \
${libdir}/pkgconfig \
${datadir}/aclocal \
${bindir}/*-config"
php.inc:
EXTRA_OECONF_append = " --with-curl=${libdir}/.."
DEPENDS_${PN} += "libcurl-dev libcurl-dev-native"
PHP Staging Directory:
/installeddeps/curl-native
/installeddeps/curl-native.b77f37db31cf2391919a12c5c9774bff
/installeddeps/curl-native.complete
/usr/share/aclocal/libcurl.m4
/usr/bin/curl-config
/usr/bin/crossscripts/curl-config
/usr/bin/curl
/usr/lib/pkgconfig/libcurl.pc
/usr/lib/libcurl.so
/usr/lib/libcurl.a
/usr/lib/libcurl.so.4.4.0
/usr/lib/libcurl.so.4
/usr/include/curl
/usr/include/curl/curl.h
/usr/include/curl/curlrules.h
/usr/include/curl/curlbuild.h
/usr/include/curl/curlver.h
/usr/include/curl/easy.h
According to php manual, PHP/cURL feature is enabled at php configuration stage with --with-curl=[dir] option.
I checked the main recipe include file php.inc and couldn't find such configuration option. So, try creating in your working layer php_%.bbappend file with (or add this directly to the bottom of php.inc to test):
EXTRA_OECONF_append_class-target = " --with-curl=${STAGING_LIBDIR}/.."
DEPENDS_append_class-target = " curl"
Note, that curl package among DEPENDS because it is needed at build stage.
I don't think you need to update curl recipe with PACKAGES and FILES, pkg_config should take care

Magento patch failing to install

When downloading and running the Magento PHP 5.4 support patch (Magento-CE-v1.7.0.0-1.7.0.2) from http://www.magentocommerce.com/download, running the script using sh PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh we receive this error:
$ sh PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh
: command not found_1.12.0.0_v1.sh: line 7:
'ATCH_SUPEE-2629_EE_1.12.0.0_v1.sh: line 9: syntax error near unexpected token `{
'ATCH_SUPEE-2629_EE_1.12.0.0_v1.sh: line 9: `_check_installed_tools() {
Strangely, line 7 of the script is blank (here's the head of the file):
#!/bin/bash
# Patch apllying tool template
# v0.1.2
# (c) Copyright 2013. Magento Inc.
#
# DO NOT CHANGE ANY LINE IN THIS FILE.
# 1. Check required system tools
_check_installed_tools() {
local missed=""
We tried the download in Windows and Mac, in Firefox and Chrome to rule out any encoding problems caused by the download process. The patch seems to be very new - Added Jan 17, 2014
We're running Magento Community Edition 1.7.0.2
Edit
We've tried running the .sh file with bash as well but receive the same response.
Interestingly when the click "download", Magento shows the .sh source in the browser so we tried various combinations of view-source then save; copying the text from the browser window and saving it to a text file. None of these solved the problem although one changed the error message to:
$ sh PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh
Checking if patch can be applied/reverted successfully...
/usr/bin/patch: **** malformed patch at line 238:
ERROR: Patch can't be applied/reverted successfully.
Line 238 is the blank comment line here:
+/**
+ * Abstract helper class for {#link Zend_Pdf_FileParser} that provides the
+ * data source for parsing.
+ *
+ * Concrete subclasses allow for parsing of in-memory, filesystem, and other
+ * sources through a common API. These subclasses also take care of error
+ * handling and other mundane tasks.
We also tried the VI step mentioned here - :set ff unix
http://www.magentocommerce.com/boards/viewthread/864518
The error then changed to:
$ sh PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh
Checking if patch can be applied/reverted successfully...
ERROR: Patch can't be applied/reverted successfully.
patching file app/code/core/Mage/Catalog/Model/Product.php
Hunk #1 FAILED at 1936.
1 out of 1 hunk FAILED -- saving rejects to file app/code/core/Mage/Catalog/Model/Product.php.rej
patching file app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
Hunk #1 FAILED at 43.
1 out of 1 hunk FAILED -- saving rejects to file app/code/core/Mage/Core/Controller/Varien/Router/Standard.php.rej
patching file app/code/core/Mage/Install/etc/config.xml
patching file app/code/core/Zend/Pdf/FileParserDataSource.php
It turns out that this error is given when the patch file (not the file being patched) has line endings which do not match the system on which it is being run.
eg: You will see this error when:
You are running on Linux
Your patch file has Windows line endings
I changed the patch file to have Unix line endings using Sublime:
View > Line Endings > Unix
See also Error patching Magento 1.7.1 Hunk #1 Failed at

Enable PCNTL in Ubuntu PHP - test fails

I need help on How to: Enable PCNTL in Ubuntu PHP.
$ mkdir /tmp/phpsource
$ cd /tmp/phpsource
$ wget http://museum.php.net/php5/php-5.3.2.tar.gz
$ tar xvf php-5.3.2.tar.gz
$ cd php-5.3.2/ext/pcntl
$ phpize -bash: phpize: command not found
Everything went fine until I tried to run phpize! And then I get the error '-bash: phpize: command not found' ?? Any ideas?
UPDATE ran:
$ sudo apt-get update
and then ran:
$ sudo apt-get install php5-dev
With the help of Nick I managed to finish the procedure. But 'make test' fails???
$ phpize
$ ./configure
$ make
$ cp modules/pcntl.so /usr/lib/php5/20090626/
$ echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini
$ make test - FAILED!
HELP: I typed 'echo "extension=pcntl.so > /etc/php5/conf.d/pcntl.ini' instead of 'echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini' the first time I ran this. Is that BAD?
--------------------------------- Make TEst Error Messages --------------------------------------
PHP Deprecated: Comments starting with '#' are deprecated in /tmp/phpsource/php-5.3.2/ext/pcntl/tmp-php.ini on line 1850 in Unknown on line 0
PHP Deprecated: Comments starting with '#' are deprecated in /tmp/phpsource/php-5.3.2/ext/pcntl/tmp-php.ini on line 1852 in Unknown on line 0
PHP Deprecated: Comments starting with '#' are deprecated in /tmp/phpsource/php-5.3.2/ext/pcntl/tmp-php.ini on line 1850 in Unknown on line 0
PHP Deprecated: Comments starting with '#' are deprecated in /tmp/phpsource/php-5.3.2/ext/pcntl/tmp-php.ini on line 1852 in Unknown on line 0
PHP Warning: Module 'pcntl' already loaded in Unknown on line 0
Warning: Module 'pcntl' already loaded in Unknown on line 0
PHP Deprecated: Comments starting with '#' are deprecated in /tmp/phpsource/php-5.3.2/ext/pcntl/tmp-php.ini on line 1850 in Unknown on line 0
PHP Deprecated: Comments starting with '#' are deprecated in /tmp/phpsource/php-5.3.2/ext/pcntl/tmp-php.ini on line 1852 in Unknown on line 0
PHP Warning: Module 'pcntl' already loaded in Unknown on line 0
Warning: Module 'pcntl' already loaded in Unknown on line 0
=====================================================================
PHP : /usr/bin/php
PHP_SAPI : cli
PHP_VERSION : 5.3.2-1ubuntu4.18
ZEND_VERSION: 2.3.0
PHP_OS : Linux - Linux lvps217-8-253-63.vps.webfusion.co.uk 2.6.32-042stab068.8 #1 SMP Fri Dec 7 17:06:14 MSK 2012 x86_64
INI actual : /tmp/phpsource/php-5.3.2/ext/pcntl/tmp-php.ini
More .INIs :
CWD : /tmp/phpsource/php-5.3.2/ext/pcntl
Extra dirs :
VALGRIND : Not used
=====================================================================
TIME START 2013-01-02 23:05:56
=====================================================================
FAIL Test pcntl wait functionality [tests/001.phpt]
FAIL pcntl: pcntl_sigprocmask(), pcntl_sigwaitinfo(), pcntl_sigtimedwait() [tests/002.phpt]
FAIL pcntl: SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK [tests/003.phpt]
FAIL Bug #47566 (return value of pcntl_wexitstatus()) [tests/bug47566.phpt]
FAIL pcntl_alarm() [tests/pcntl_alarm.phpt]
FAIL pcntl_exec() [tests/pcntl_exec.phpt]
FAIL pcntl_exec() 2 [tests/pcntl_exec_2.phpt]
FAIL pcntl_exec() 3 [tests/pcntl_exec_3.phpt]
FAIL Test function pcntl_fork() by calling it with its expected arguments [tests/pcntl_fork_basic.phpt]
FAIL Test function pcntl_fork() by testing the process isolation in the forking hierarchy father -> son -> grandson where father can not knows his grandson [tests/pcntl_fork_variation.phpt]
FAIL pcntl_signal() [tests/pcntl_signal.phpt]
FAIL pcnt_signal_dispatch() [tests/pcntl_signal_dispatch.phpt]
FAIL pcntl_wait() [tests/pcntl_wait.phpt]
FAIL Closures as a signal handler [tests/signal_closure_handler.phpt]
=====================================================================
TIME END 2013-01-02 23:05:59
=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped : 0
Exts tested : 44
---------------------------------------------------------------------
Number of tests : 14 14
Tests skipped : 0 ( 0.0%) --------
Tests warned : 0 ( 0.0%) ( 0.0%)
Tests failed : 14 (100.0%) (100.0%)
Expected fail : 0 ( 0.0%) ( 0.0%)
Tests passed : 0 ( 0.0%) ( 0.0%)
---------------------------------------------------------------------
Time taken : 3 seconds
=====================================================================
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test pcntl wait functionality [tests/001.phpt]
pcntl: pcntl_sigprocmask(), pcntl_sigwaitinfo(), pcntl_sigtimedwait() [tests/002.phpt]
pcntl: SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK [tests/003.phpt]
Bug #47566 (return value of pcntl_wexitstatus()) [tests/bug47566.phpt]
pcntl_alarm() [tests/pcntl_alarm.phpt]
pcntl_exec() [tests/pcntl_exec.phpt]
pcntl_exec() 2 [tests/pcntl_exec_2.phpt]
pcntl_exec() 3 [tests/pcntl_exec_3.phpt]
Test function pcntl_fork() by calling it with its expected arguments [tests/pcntl_fork_basic.phpt]
Test function pcntl_fork() by testing the process isolation in the forking hierarchy father -> son -> grandson where father can not knows his grandson [tests/pcntl_fork_variation.phpt]
pcntl_signal() [tests/pcntl_signal.phpt]
pcnt_signal_dispatch() [tests/pcntl_signal_dispatch.phpt]
pcntl_wait() [tests/pcntl_wait.phpt]
Closures as a signal handler [tests/signal_closure_handler.phpt]
ANY ideas!?!
Carl
Here's what I've found in Ubuntu 12.04:
Check your PHP.ini for the pnctl functions being disabled.
disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority
phpinfo reports the function is already loaded but it will not actually work without putting the pcntl.ini file into /etc/php5/conf.d.
Sadly, this causes 'module already loaded' errors every time PHP session cleanup cron in /etc/cron.d kicks off, but PCNTL won't function without both of these pieces in place, and so far I haven't found a good solution to disable the 'already loaded' error. Its messy, and ugly, and spams my root mail, and when I can find a solution, I will post it. I've only run into this problem in 12.04 so far.
UPDATE
I hacked my /usr/lib/php5/maxlifetime script file to stop spamming with pnctl errors (PHP Warning: Module 'pcntl' already loaded in Unknown on line 0). Here are my edits - I specifically added in the 'E_DEPRECATED' line to quiet the messages.
Line 8:
cur=$(php5 -c /etc/php5/${sapi}/php.ini -d "error_reporting='E_ALL & ~E_DEPRECATED'" -r 'print ini_get("session.gc_maxlifetime");' 2> /dev/null)
There is some steps like this:
(my OS is debian7.2 xfce x86).
1: i install pcntl like this
#mkdir php
#cd php
#apt-get source php5
#cd php5-5.4.4/ext/pcntl
#phpize
#./configure
#make
#echo "extension=pcntl.so" > /etc/php5/mods-available/pcntl.ini
#ln -s /etc/php5/mods-available/pcntl.ini /etc/php5/conf.d/pcntl.ini
2: when is restart nginx or apache2, the php get one warning.
"PHP Warning: Module ‘pcntl’ already loaded in Unknown on line 0"
3: so i
"rm -rf /etc/php5/mods-available/pcntl.ini and
/etc/php5/conf.d/pcntl.ini"
4: edit the "php.ini" file .
a.apache2, it's in "/etc/php5/apache2/php.ini"
b.cgi like nginx,it's in "/etc/php5/cgi/php.ini"
make the
"disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited..."
comments, add " ; " in front of "disable_functions".
restart your server and the warning gone.good luck.
On my dev machine with ubuntu 12.10 (and earlier versions too) pcntl is/was already enabled.
$ php -m | grep pcntl
pcntl
I guess thats the problem:
PHP Warning: Module 'pcntl' already loaded in Unknown on line 0
So just don't install it again.
I NEEDED to restart the server! And now it works! Doh.. Thanks for everybodys input.
In Ubuntu 15.04, the pcntl is installed in the php CLI, but disabled by default. To enable, edit /etc/php5/cli/php.ini and comment out the line:
disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
If you want these enabled in apache2, then edit the file /etc/php5/apache2/php.ini and make the same change.
It may be advisable to only remove the functions you need to use, in order to preserve as much of the security restrictions as possible.

PSR2 with class declarations extending classes with namespaces in PHP Code Sniffer

I've hit a problem with PHPCS using the PSR2 standard. Have searched high and low but to my surprise I can't find anyone reporting the same issue.
Say I have a class declaration as follows:
<?php
class MyChildClass extends \SomeNameSpace\MyParentClass
{
}
Then I run it through PHPCS with:
bash-3.2$ phpcs -s --standard=PSR2 test.php
FILE: test.php
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
3 | ERROR | Expected 0 spaces between "SomeNameSpace" and comma; $1 found
| | (PSR2.Classes.ClassDeclaration.SpaceBeforeComma)
3 | ERROR | Expected 1 space before "MyParentClass"; 13 found
| | (PSR2.Classes.ClassDeclaration.SpaceBeforeName)
--------------------------------------------------------------------------------
Time: 0 seconds, Memory: 4.00Mb
Also:
Bash-3.2$ phpcs --version
PHP_CodeSniffer version 1.3.6 (stable) by Squiz Pty Ltd. (http://www.squiz.net)
Has anyone come across this? Am I doing something wrong? Otherwise I'm going head first into the sniffer code - which doesn't feel right.
The PSR-1 and PSR-2 standard inside the current release of PHP_CodeSniffer are not complete. I didn't ever mention them in the release notes so people obviously either just found them, or they are talking about the current dev version, where they are complete.
If you want to try out the complete version of PSR-2 inside PHP_CodeSniffer, you'll need to clone the git repo and use it directly:
git clone git://github.com/squizlabs/PHP_CodeSniffer.git
cd PHP_CodeSniffer
php scripts/phpcs --standard=PSR2 /path/to/code
Or you can wait for the official release, which I'm planning for sometime next week, assuming no major issues are reported.
If you run the latest dev version on the code you supplied, you'll get this:
2:PHP_CodeSniffer gsherwood$ php scripts/phpcs --standard=psr2 temp.php
FILE: /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/temp.php
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
3 | ERROR | Each class must be in a namespace of at least one level (a
| | top-level vendor name)
5 | ERROR | Expected 1 blank line at end of file; 0 found
--------------------------------------------------------------------------------
Time: 0 seconds, Memory: 4.25Mb
Hope that helps.

Categories