Skip to content

Commit a16c989

Browse files
authored
Merge pull request #159 from PHPCSStandards/develop
Release 1.0.0-alpha3
2 parents 7fa2a5c + 823dbb4 commit a16c989

File tree

182 files changed

+27631
-18564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+27631
-18564
lines changed

.travis.yml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
os: linux
12
dist: trusty
23

34
language: php
@@ -10,6 +11,7 @@ cache:
1011
- $HOME/.composer/cache/files
1112
# Cache directory for more recent Composer versions.
1213
- $HOME/.cache/composer/files
14+
- /home/travis/.rvm/
1315

1416
php:
1517
- 5.5
@@ -31,6 +33,8 @@ env:
3133
# See: https://docs.travis-ci.com/user/conditions-v1
3234
stages:
3335
- name: sniff
36+
- name: docs
37+
if: branch IN (master)
3438
- name: quicktest
3539
if: type = push AND branch NOT IN (master, develop)
3640
- name: test
@@ -66,6 +70,23 @@ jobs:
6670
# Check the code-style consistency of the xml files.
6771
- diff -B ./PHPCSUtils/ruleset.xml <(xmllint --format "./PHPCSUtils/ruleset.xml")
6872
- diff -B ./PHPCS23Utils/ruleset.xml <(xmllint --format "./PHPCS23Utils/ruleset.xml")
73+
after_success: skip
74+
75+
#### DOCUMENTATION SITE TESTING STAGE ####
76+
- stage: docs
77+
language: ruby
78+
cache: bundler
79+
rvm: 2.5.8
80+
before_install: skip
81+
install:
82+
- cd ./docs
83+
- gem install bundler
84+
- bundle install
85+
before_script: skip
86+
script:
87+
# Test the documentation generation.
88+
- bundle exec jekyll build
89+
after_success: skip
6990

7091
#### QUICK TEST STAGE ####
7192
# This is a much quicker test which only runs the unit tests and linting against the low/high
@@ -109,6 +130,9 @@ jobs:
109130
- php: 7.2
110131
env: PHPCS_VERSION="3.2.0"
111132

133+
- php: 7.4
134+
env: PHPCS_VERSION="4.0.x-dev@dev"
135+
112136
- php: "nightly"
113137
env: PHPCS_VERSION="n/a" LINT=1
114138

@@ -132,19 +156,20 @@ jobs:
132156
allow_failures:
133157
# Allow failures for unstable builds.
134158
- php: "nightly"
159+
- env: PHPCS_VERSION="4.0.x-dev@dev"
135160

136161

137162
before_install:
138163
# Speed up build time by disabling Xdebug when its not needed.
139164
- |
140-
if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Coverage" ]]; then
165+
if [[ "${TRAVIS_BUILD_STAGE_NAME^}" != "Coverage" ]]; then
141166
phpenv config-rm xdebug.ini || echo 'No xdebug config.'
142167
fi
143168
144169
# On stable PHPCS versions, allow for PHP deprecation notices.
145170
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
146171
- |
147-
if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Sniff" && $PHPCS_VERSION != "dev-master" && "$PHPCS_VERSION" != "n/a" ]]; then
172+
if [[ "${TRAVIS_BUILD_STAGE_NAME^}" != "Sniff" && $PHPCS_VERSION != "dev-master" && "$PHPCS_VERSION" != "n/a" ]]; then
148173
echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
149174
fi
150175
@@ -158,7 +183,7 @@ install:
158183
composer require --no-update --no-scripts squizlabs/php_codesniffer:${PHPCS_VERSION}
159184
fi
160185
- |
161-
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then
186+
if [[ "${TRAVIS_BUILD_STAGE_NAME^}" == "Coverage" ]]; then
162187
composer require --dev --no-update --no-suggest --no-scripts php-coveralls/php-coveralls:${COVERALLS_VERSION}
163188
fi
164189
- |
@@ -173,7 +198,7 @@ install:
173198

174199

175200
before_script:
176-
- if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then mkdir -p build/logs; fi
201+
- if [[ "${TRAVIS_BUILD_STAGE_NAME^}" == "Coverage" ]]; then mkdir -p build/logs; fi
177202
- phpenv rehash
178203

179204

@@ -183,18 +208,18 @@ script:
183208

184209
# Run the unit tests.
185210
- |
186-
if [[ $PHPCS_VERSION != "n/a" && "$TRAVIS_BUILD_STAGE_NAME" != "Coverage" ]]; then
211+
if [[ $PHPCS_VERSION != "n/a" && "${TRAVIS_BUILD_STAGE_NAME^}" != "Coverage" ]]; then
187212
composer test
188-
elif [[ $PHPCS_VERSION != "n/a" && "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" ]]; then
213+
elif [[ $PHPCS_VERSION != "n/a" && "${TRAVIS_BUILD_STAGE_NAME^}" == "Coverage" ]]; then
189214
composer coverage
190215
fi
191216
192217
after_success:
193218
- |
194-
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" && $COVERALLS_VERSION == "^1.0" ]]; then
219+
if [[ "${TRAVIS_BUILD_STAGE_NAME^}" == "Coverage" && $COVERALLS_VERSION == "^1.0" ]]; then
195220
php vendor/bin/coveralls -v -x build/logs/clover.xml
196221
fi
197222
- |
198-
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Coverage" && $COVERALLS_VERSION == "^2.0" ]]; then
223+
if [[ "${TRAVIS_BUILD_STAGE_NAME^}" == "Coverage" && $COVERALLS_VERSION == "^2.0" ]]; then
199224
php vendor/bin/php-coveralls -v -x build/logs/clover.xml
200225
fi

CHANGELOG.md

Lines changed: 169 additions & 35 deletions
Large diffs are not rendered by default.

PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ abstract class AbstractArrayDeclarationSniff implements Sniff
6868
* A multi-dimentional array with information on each array item.
6969
*
7070
* The array index is 1-based and contains the following information on each array item:
71-
* - 'start' : The stack pointer to the first token in the array item.
72-
* - 'end' : The stack pointer to the first token in the array item.
73-
* - 'raw' : A string with the contents of all tokens between `start` and `end`.
74-
* - 'clean' : Same as `raw`, but all comment tokens have been stripped out.
71+
* ```php
72+
* 1 => array(
73+
* 'start' => int, // The stack pointer to the first token in the array item.
74+
* 'end' => int, // The stack pointer to the last token in the array item.
75+
* 'raw' => string, // A string with the contents of all tokens between `start` and `end`.
76+
* 'clean' => string, // Same as `raw`, but all comment tokens have been stripped out.
77+
* )
78+
* ```
7579
*
7680
* @since 1.0.0
7781
*
@@ -100,6 +104,8 @@ abstract class AbstractArrayDeclarationSniff implements Sniff
100104
/**
101105
* List of tokens which can safely be used with an eval() expression.
102106
*
107+
* This list gets enhanced with additional token groups in the constructor.
108+
*
103109
* @since 1.0.0
104110
*
105111
* @var array
@@ -161,7 +167,7 @@ public function register()
161167
* Processes this test when one of its tokens is encountered.
162168
*
163169
* This method fills the properties with relevant information for examining the array
164-
* and then passes off to the `processArray()` method.
170+
* and then passes off to the {@see AbstractArrayDeclarationSniff::processArray()} method.
165171
*
166172
* @since 1.0.0
167173
*
@@ -203,7 +209,19 @@ final public function process(File $phpcsFile, $stackPtr)
203209
/**
204210
* Process every part of the array declaration.
205211
*
206-
* This contains the default logic for the sniff, but can be overloaded in a concrete child class
212+
* Controller which calls the individual `process...()` methods for each part of the array.
213+
*
214+
* The method starts by calling the {@see AbstractArrayDeclarationSniff::processOpenClose()} method
215+
* and subsequently calls the following methods for each array item:
216+
*
217+
* Unkeyed arrays | Keyed arrays
218+
* -------------- | ------------
219+
* processNoKey() | processKey()
220+
* - | processArrow()
221+
* processValue() | processValue()
222+
* processComma() | processComma()
223+
*
224+
* This is the default logic for the sniff, but can be overloaded in a concrete child class
207225
* if needed.
208226
*
209227
* @since 1.0.0
@@ -224,7 +242,12 @@ public function processArray(File $phpcsFile)
224242
}
225243

226244
foreach ($this->arrayItems as $itemNr => $arrayItem) {
227-
$arrowPtr = Arrays::getDoubleArrowPtr($phpcsFile, $arrayItem['start'], $arrayItem['end']);
245+
try {
246+
$arrowPtr = Arrays::getDoubleArrowPtr($phpcsFile, $arrayItem['start'], $arrayItem['end']);
247+
} catch (RuntimeException $e) {
248+
// Parse error: empty array item. Ignore.
249+
continue;
250+
}
228251

229252
if ($arrowPtr !== false) {
230253
if ($this->processKey($phpcsFile, $arrayItem['start'], ($arrowPtr - 1), $itemNr) === true) {
@@ -260,7 +283,7 @@ public function processArray(File $phpcsFile)
260283
/**
261284
* Process the array opener and closer.
262285
*
263-
* Optional method to be implemented in concrete child classes.
286+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
264287
*
265288
* @since 1.0.0
266289
*
@@ -271,7 +294,9 @@ public function processArray(File $phpcsFile)
271294
* @param int $openPtr The position of the array opener token in the token stack.
272295
* @param int $closePtr The position of the array closer token in the token stack.
273296
*
274-
* @return true|void Returning `true` will short-circuit the sniff and stop processing.
297+
* @return true|void Returning `TRUE` will short-circuit the sniff and stop processing.
298+
* In effect, this means that the sniff will not examine the individual
299+
* array items if `TRUE` is returned.
275300
*/
276301
public function processOpenClose(File $phpcsFile, $openPtr, $closePtr)
277302
{
@@ -280,10 +305,10 @@ public function processOpenClose(File $phpcsFile, $openPtr, $closePtr)
280305
/**
281306
* Process the tokens in an array key.
282307
*
283-
* Optional method to be implemented in concrete child classes.
308+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
284309
*
285-
* The $startPtr and $endPtr do not discount whitespace or comments, but are all inclusive to
286-
* allow examining all tokens in an array key.
310+
* Note: The `$startPtr` and `$endPtr` do not discount whitespace or comments, but are all inclusive
311+
* to allow for examining all tokens in an array key.
287312
*
288313
* @since 1.0.0
289314
*
@@ -300,7 +325,9 @@ public function processOpenClose(File $phpcsFile, $openPtr, $closePtr)
300325
* @param int $itemNr Which item in the array is being handled.
301326
* 1-based, i.e. the first item is item 1, the second 2 etc.
302327
*
303-
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
328+
* @return true|void Returning `TRUE` will short-circuit the array item loop and stop processing.
329+
* In effect, this means that the sniff will not examine the double arrow, the array
330+
* value or comma for this array item and will not process any array items after this one.
304331
*/
305332
public function processKey(File $phpcsFile, $startPtr, $endPtr, $itemNr)
306333
{
@@ -309,12 +336,17 @@ public function processKey(File $phpcsFile, $startPtr, $endPtr, $itemNr)
309336
/**
310337
* Process an array item without an array key.
311338
*
312-
* Optional method to be implemented in concrete child classes.
339+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
340+
*
341+
* Note: This method is _not_ intended for processing the array _value_. Use the
342+
* {@see AbstractArrayDeclarationSniff::processValue()} method to implement processing of the array value.
313343
*
314344
* @since 1.0.0
315345
*
316346
* @codeCoverageIgnore
317347
*
348+
* @see \PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff::processValue() Method to process the array value.
349+
*
318350
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the
319351
* token was found.
320352
* @param int $startPtr The stack pointer to the first token in the array item,
@@ -323,7 +355,9 @@ public function processKey(File $phpcsFile, $startPtr, $endPtr, $itemNr)
323355
* @param int $itemNr Which item in the array is being handled.
324356
* 1-based, i.e. the first item is item 1, the second 2 etc.
325357
*
326-
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
358+
* @return true|void Returning `TRUE` will short-circuit the array item loop and stop processing.
359+
* In effect, this means that the sniff will not examine the array value or
360+
* comma for this array item and will not process any array items after this one.
327361
*/
328362
public function processNoKey(File $phpcsFile, $startPtr, $itemNr)
329363
{
@@ -332,7 +366,7 @@ public function processNoKey(File $phpcsFile, $startPtr, $itemNr)
332366
/**
333367
* Process the double arrow.
334368
*
335-
* Optional method to be implemented in concrete child classes.
369+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
336370
*
337371
* @since 1.0.0
338372
*
@@ -344,7 +378,9 @@ public function processNoKey(File $phpcsFile, $startPtr, $itemNr)
344378
* @param int $itemNr Which item in the array is being handled.
345379
* 1-based, i.e. the first item is item 1, the second 2 etc.
346380
*
347-
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
381+
* @return true|void Returning `TRUE` will short-circuit the array item loop and stop processing.
382+
* In effect, this means that the sniff will not examine the array value or
383+
* comma for this array item and will not process any array items after this one.
348384
*/
349385
public function processArrow(File $phpcsFile, $arrowPtr, $itemNr)
350386
{
@@ -353,10 +389,10 @@ public function processArrow(File $phpcsFile, $arrowPtr, $itemNr)
353389
/**
354390
* Process the tokens in an array value.
355391
*
356-
* Optional method to be implemented in concrete child classes.
392+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
357393
*
358-
* The $startPtr and $endPtr do not discount whitespace or comments, but are all inclusive to
359-
* allow examining all tokens in an array value.
394+
* Note: The `$startPtr` and `$endPtr` do not discount whitespace or comments, but are all inclusive
395+
* to allow for examining all tokens in an array value.
360396
*
361397
* @since 1.0.0
362398
*
@@ -371,7 +407,9 @@ public function processArrow(File $phpcsFile, $arrowPtr, $itemNr)
371407
* @param int $itemNr Which item in the array is being handled.
372408
* 1-based, i.e. the first item is item 1, the second 2 etc.
373409
*
374-
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
410+
* @return true|void Returning `TRUE` will short-circuit the array item loop and stop processing.
411+
* In effect, this means that the sniff will not examine the comma for this
412+
* array item and will not process any array items after this one.
375413
*/
376414
public function processValue(File $phpcsFile, $startPtr, $endPtr, $itemNr)
377415
{
@@ -380,7 +418,7 @@ public function processValue(File $phpcsFile, $startPtr, $endPtr, $itemNr)
380418
/**
381419
* Process the comma after an array item.
382420
*
383-
* Optional method to be implemented in concrete child classes.
421+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
384422
*
385423
* @since 1.0.0
386424
*
@@ -392,7 +430,9 @@ public function processValue(File $phpcsFile, $startPtr, $endPtr, $itemNr)
392430
* @param int $itemNr Which item in the array is being handled.
393431
* 1-based, i.e. the first item is item 1, the second 2 etc.
394432
*
395-
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
433+
* @return true|void Returning `TRUE` will short-circuit the array item loop and stop processing.
434+
* In effect, this means that the sniff will not process any array items
435+
* after this one.
396436
*/
397437
public function processComma(File $phpcsFile, $commaPtr, $itemNr)
398438
{
@@ -401,7 +441,8 @@ public function processComma(File $phpcsFile, $commaPtr, $itemNr)
401441
/**
402442
* Determine what the actual array key would be.
403443
*
404-
* Optional helper function for processsing array keys in the processKey() function.
444+
* Helper function for processsing array keys in the processKey() function.
445+
* Using this method is up to the sniff implementation in the child class.
405446
*
406447
* @since 1.0.0
407448
*

0 commit comments

Comments
 (0)