Skip to content

Commit

Permalink
Merge branch 'master' into issue#2036
Browse files Browse the repository at this point in the history
  • Loading branch information
gmponos committed Nov 13, 2018
2 parents 82f63e0 + f693a3f commit a829bf0
Show file tree
Hide file tree
Showing 148 changed files with 3,850 additions and 502 deletions.
21 changes: 20 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ matrix:
- php: 5.6
- php: 7.0
- php: 7.0
env: CUSTOM_INI=1
env: CUSTOM_INI=1 XMLLINT=1
addons:
apt:
packages:
- libxml2-utils
- php: 7.1
- php: 7.2
- php: 7.3
- php: nightly

allow_failures:
- php: nightly

before_install:
- export XMLLINT_INDENT=" "
# Speed up build time by disabling Xdebug when its not needed.
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'

Expand All @@ -36,3 +42,16 @@ script:
- if [[ $CUSTOM_INI != "1" ]]; then composer validate --no-check-all --strict; fi
- if [[ $CUSTOM_INI != "1" ]]; then php scripts/build-phar.php; fi
- if [[ $CUSTOM_INI != "1" ]]; then php phpcs.phar; fi
# Validate the xml ruleset files.
# @link http://xmlsoft.org/xmllint.html
- if [[ $XMLLINT == "1" ]]; then xmllint --noout --schema phpcs.xsd ./src/Standards/*/ruleset.xml; fi
# Check the code-style consistency of the xml files.
- if [[ $XMLLINT == "1" ]]; then diff -B ./phpcs.xml.dist <(xmllint --format "./phpcs.xml.dist"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/Generic/ruleset.xml <(xmllint --format "./src/Standards/Generic/ruleset.xml"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/MySource/ruleset.xml <(xmllint --format "./src/Standards/MySource/ruleset.xml"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/PEAR/ruleset.xml <(xmllint --format "./src/Standards/PEAR/ruleset.xml"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/PSR1/ruleset.xml <(xmllint --format "./src/Standards/PSR1/ruleset.xml"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/PSR2/ruleset.xml <(xmllint --format "./src/Standards/PSR2/ruleset.xml"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/PSR12/ruleset.xml <(xmllint --format "./src/Standards/PSR12/ruleset.xml"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/Squiz/ruleset.xml <(xmllint --format "./src/Standards/Squiz/ruleset.xml"); fi
- if [[ $XMLLINT == "1" ]]; then diff -B ./src/Standards/Zend/ruleset.xml <(xmllint --format "./src/Standards/Zend/ruleset.xml"); fi
209 changes: 183 additions & 26 deletions package.xml

Large diffs are not rendered by default.

73 changes: 37 additions & 36 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>The coding standard for PHP_CodeSniffer itself.</description>

<file>autoload.php</file>
Expand All @@ -11,8 +11,8 @@
<exclude-pattern>*/Standards/*/Tests/*\.(inc|css|js)</exclude-pattern>

<arg name="basepath" value="."/>
<arg name="colors" />
<arg name="parallel" value="75" />
<arg name="colors"/>
<arg name="parallel" value="75"/>
<arg value="np"/>

<!-- Don't hide tokenizer exceptions -->
Expand All @@ -22,40 +22,40 @@

<!-- Include the whole PEAR standard -->
<rule ref="PEAR">
<exclude name="PEAR.NamingConventions.ValidFunctionName" />
<exclude name="PEAR.NamingConventions.ValidVariableName" />
<exclude name="PEAR.Commenting.ClassComment" />
<exclude name="PEAR.Commenting.FileComment.MissingCategoryTag" />
<exclude name="PEAR.Commenting.FileComment.MissingPackageTag" />
<exclude name="PEAR.Commenting.FileComment.MissingLinkTag" />
<exclude name="PEAR.Commenting.FileComment.MissingVersion" />
<exclude name="PEAR.Commenting.InlineComment" />
<exclude name="PEAR.NamingConventions.ValidFunctionName"/>
<exclude name="PEAR.NamingConventions.ValidVariableName"/>
<exclude name="PEAR.Commenting.ClassComment"/>
<exclude name="PEAR.Commenting.FileComment.MissingCategoryTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingPackageTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingLinkTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingVersion"/>
<exclude name="PEAR.Commenting.InlineComment"/>
</rule>

<!-- Include some sniffs from other standards that don't conflict with PEAR -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing" />
<rule ref="Squiz.Arrays.ArrayDeclaration" />
<rule ref="Squiz.Commenting.ClosingDeclarationComment" />
<rule ref="Squiz.ControlStructures.ControlSignature" />
<rule ref="Squiz.ControlStructures.ElseIfDeclaration" />
<rule ref="Squiz.Commenting.BlockComment" />
<rule ref="Squiz.Commenting.DocCommentAlignment" />
<rule ref="Squiz.Commenting.EmptyCatchComment" />
<rule ref="Squiz.Commenting.InlineComment" />
<rule ref="Squiz.Commenting.LongConditionClosingComment" />
<rule ref="Squiz.Commenting.PostStatementComment" />
<rule ref="Squiz.Commenting.VariableComment" />
<rule ref="Squiz.Formatting.OperatorBracket" />
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing" />
<rule ref="Squiz.Operators.ComparisonOperatorUsage" />
<rule ref="Squiz.PHP.DisallowInlineIf" />
<rule ref="Squiz.Scope.MethodScope" />
<rule ref="Squiz.Strings.ConcatenationSpacing" />
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing" />
<rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace" />
<rule ref="Squiz.WhiteSpace.FunctionSpacing" />
<rule ref="Squiz.WhiteSpace.OperatorSpacing" />
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Arrays.ArrayDeclaration"/>
<rule ref="Squiz.Commenting.ClosingDeclarationComment"/>
<rule ref="Squiz.ControlStructures.ControlSignature"/>
<rule ref="Squiz.ControlStructures.ElseIfDeclaration"/>
<rule ref="Squiz.Commenting.BlockComment"/>
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
<rule ref="Squiz.Commenting.EmptyCatchComment"/>
<rule ref="Squiz.Commenting.InlineComment"/>
<rule ref="Squiz.Commenting.LongConditionClosingComment"/>
<rule ref="Squiz.Commenting.PostStatementComment"/>
<rule ref="Squiz.Commenting.VariableComment"/>
<rule ref="Squiz.Formatting.OperatorBracket"/>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"/>
<rule ref="Squiz.Operators.ComparisonOperatorUsage"/>
<rule ref="Squiz.PHP.DisallowInlineIf"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Strings.ConcatenationSpacing"/>
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing"/>
<rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace"/>
<rule ref="Squiz.WhiteSpace.FunctionSpacing"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
Expand All @@ -65,6 +65,7 @@
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
<rule ref="PSR2.Classes.PropertyDeclaration"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>
<rule ref="PSR2.Files.EndFileNewline"/>
Expand All @@ -77,7 +78,7 @@
</properties>
</rule>

<!-- We use custom indent rules for arrays -->
<!-- We use custom indent rules for arrays -->
<rule ref="Generic.Arrays.ArrayIndent"/>
<rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned">
<severity>0</severity>
Expand All @@ -93,7 +94,7 @@
</rule>

<!-- Check var names, but we don't want leading underscores for private vars -->
<rule ref="Squiz.NamingConventions.ValidVariableName" />
<rule ref="Squiz.NamingConventions.ValidVariableName"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
<severity>0</severity>
</rule>
Expand Down
8 changes: 8 additions & 0 deletions phpcs.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
</xs:attribute>
<xs:attribute name="name" type="xs:string" use="required"></xs:attribute>
<xs:attribute name="value" type="xs:string"></xs:attribute>
<xs:attribute name="extend">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="true"/>
<xs:enumeration value="false"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Config
*
* @var string
*/
const VERSION = '3.3.2';
const VERSION = '3.4.0';

/**
* Package stability; either stable, beta or alpha.
Expand Down
26 changes: 26 additions & 0 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ public function getMethodParameters($stackPtr)
* 'is_abstract' => false, // true if the abstract keyword was found.
* 'is_final' => false, // true if the final keyword was found.
* 'is_static' => false, // true if the static keyword was found.
* 'has_body' => false, // true if the method has a body
* );
* </code>
*
Expand Down Expand Up @@ -1541,6 +1542,7 @@ public function getMethodProperties($stackPtr)
$returnType = '';
$returnTypeToken = false;
$nullableReturnType = false;
$hasBody = true;

if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true) {
$scopeOpener = null;
Expand Down Expand Up @@ -1576,6 +1578,9 @@ public function getMethodProperties($stackPtr)
$returnType .= $this->tokens[$i]['content'];
}
}

$end = $this->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $this->tokens[$stackPtr]['parenthesis_closer']);
$hasBody = $this->tokens[$end]['code'] === T_OPEN_CURLY_BRACKET;
}//end if

if ($returnType !== '' && $nullableReturnType === true) {
Expand All @@ -1591,6 +1596,7 @@ public function getMethodProperties($stackPtr)
'is_abstract' => $isAbstract,
'is_final' => $isFinal,
'is_static' => $isStatic,
'has_body' => $hasBody,
];

}//end getMethodProperties()
Expand Down Expand Up @@ -1650,6 +1656,18 @@ public function getMemberProperties($stackPtr)
}
}

// Make sure it's not a method parameter.
if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
$parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
$deepestOpen = array_pop($parenthesis);
if ($deepestOpen > $ptr
&& isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
&& $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
) {
throw new TokenizerException('$stackPtr is not a class member var');
}
}

$valid = [
T_PUBLIC => T_PUBLIC,
T_PRIVATE => T_PRIVATE,
Expand Down Expand Up @@ -1911,6 +1929,14 @@ public function isReference($stackPtr)
*/
public function getTokensAsString($start, $length, $origContent=false)
{
if (is_int($start) === false || isset($this->tokens[$start]) === false) {
throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
}

if (is_int($length) === false || $length <= 0) {
return '';
}

$str = '';
$end = ($start + $length);
if ($end > $this->numTokens) {
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function beginChangeset()
}

if (PHP_CODESNIFFER_VERBOSITY > 1) {
$bt = debug_backtrace();
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$sniff = $bt[1]['class'];
$line = $bt[0]['line'];

Expand Down Expand Up @@ -480,7 +480,7 @@ public function replaceToken($stackPtr, $content)
}

if (PHP_CODESNIFFER_VERBOSITY > 1) {
$bt = debug_backtrace();
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
$sniff = $bt[2]['class'];
$line = $bt[1]['line'];
Expand Down Expand Up @@ -592,7 +592,7 @@ public function revertToken($stackPtr)
}

if (PHP_CODESNIFFER_VERBOSITY > 1) {
$bt = debug_backtrace();
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
$sniff = $bt[2]['class'];
$line = $bt[1]['line'];
Expand Down
7 changes: 7 additions & 0 deletions src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,13 @@ private function processRule($rule, $newSniffs, $depth=0)
&& (string) $prop['type'] === 'array'
) {
$values = [];
if (isset($prop['extend']) === true
&& (string) $prop['extend'] === 'true'
&& isset($this->ruleset[$code]['properties'][$name]) === true
) {
$values = $this->ruleset[$code]['properties'][$name];
}

if (isset($prop->element) === true) {
$printValue = '';
foreach ($prop->element as $element) {
Expand Down
6 changes: 3 additions & 3 deletions src/Sniffs/AbstractPatternSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ private function parse($pattern)
$specialPattern = $this->createSkipPattern($pattern, ($i - 1));
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 2);
$i += 2;

if ($specialPattern['to'] !== 'unknown') {
$firstToken++;
Expand All @@ -794,12 +794,12 @@ private function parse($pattern)
$specialPattern = ['type' => 'string'];
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 2);
$i += 2;
} else if (substr($pattern, $i, 3) === 'EOL') {
$specialPattern = ['type' => 'newline'];
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 2);
$i += 2;
}//end if

if ($specialPattern !== false || $isLastChar === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function process(File $phpcsFile, $stackPtr)
$findTokens = [
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_NAMESPACE,
T_CLOSE_TAG,
];
Expand Down
Loading

0 comments on commit a829bf0

Please sign in to comment.