Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

New coding standard #20

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .php_cs

This file was deleted.

15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ matrix:
include:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- CS_CHECK=true
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- TEST_COVERAGE=true
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
- PATH="$HOME/.local/bin:$PATH"
- php: 7
Expand All @@ -42,21 +42,20 @@ notifications:
email: false

before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs

script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi

after_success:
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi

after_script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ To do so:

## Running Coding Standards Checks

This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding
This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding
standards checks, and provides configuration for our selected checks.
`php-cs-fixer` is installed by default via Composer.
`phpcs` is installed by default via Composer.

To run checks only:

```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs
$ composer cs-check
```

To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run`
flag:
`phpcs` also includes a tool for fixing most CS violations, `phpcbf`:


```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs
$ composer cs-fix
```

If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure
If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.

## Recommended Workflow for Contributions
Expand Down
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
"phpunit/PHPUnit": "~4.0",
"zendframework/zend-coding-standard": "~1.0.0"
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"upload-coverage": "coveralls -v"
}
}
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>
4 changes: 2 additions & 2 deletions src/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function __construct($encoding = null)
}

$encoding = strtolower($encoding);
if (!in_array($encoding, $this->supportedEncodings)) {
if (! in_array($encoding, $this->supportedEncodings)) {
throw new Exception\InvalidArgumentException(
'Value of \'' . $encoding . '\' passed to ' . get_class($this)
. ' constructor parameter is invalid. Provide an encoding supported by htmlspecialchars()'
Expand Down Expand Up @@ -321,7 +321,7 @@ protected function toUtf8($string)
$result = $this->convertEncoding($string, 'UTF-8', $this->getEncoding());
}

if (!$this->isUtf8($result)) {
if (! $this->isUtf8($result)) {
throw new Exception\RuntimeException(
sprintf('String to be escaped was not valid UTF-8 or could not be converted: %s', $result)
);
Expand Down
6 changes: 3 additions & 3 deletions test/EscaperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected function codepointToUtf8($codepoint)
public function testJavascriptEscapingEscapesOwaspRecommendedRanges()
{
$immune = [',', '.', '_']; // Exceptions to escaping ranges
for ($chr=0; $chr < 0xFF; $chr++) {
for ($chr = 0; $chr < 0xFF; $chr++) {
if ($chr >= 0x30 && $chr <= 0x39
|| $chr >= 0x41 && $chr <= 0x5A
|| $chr >= 0x61 && $chr <= 0x7A
Expand All @@ -354,7 +354,7 @@ public function testJavascriptEscapingEscapesOwaspRecommendedRanges()
public function testHtmlAttributeEscapingEscapesOwaspRecommendedRanges()
{
$immune = [',', '.', '-', '_']; // Exceptions to escaping ranges
for ($chr=0; $chr < 0xFF; $chr++) {
for ($chr = 0; $chr < 0xFF; $chr++) {
if ($chr >= 0x30 && $chr <= 0x39
|| $chr >= 0x41 && $chr <= 0x5A
|| $chr >= 0x61 && $chr <= 0x7A
Expand All @@ -379,7 +379,7 @@ public function testHtmlAttributeEscapingEscapesOwaspRecommendedRanges()
public function testCssEscapingEscapesOwaspRecommendedRanges()
{
$immune = []; // CSS has no exceptions to escaping ranges
for ($chr=0; $chr < 0xFF; $chr++) {
for ($chr = 0; $chr < 0xFF; $chr++) {
if ($chr >= 0x30 && $chr <= 0x39
|| $chr >= 0x41 && $chr <= 0x5A
|| $chr >= 0x61 && $chr <= 0x7A
Expand Down