Skip to content

Commit

Permalink
Merge bc34e6a into b765703
Browse files Browse the repository at this point in the history
  • Loading branch information
sspat committed Dec 26, 2020
2 parents b765703 + bc34e6a commit e42589c
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 54 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Check Coding Standards"
on:
pull_request:
push:
branches:
- "master"
jobs:
coding-standards:
name: "Check Coding Standards"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
dependencies:
- "locked"
php-version:
- "7.4"
operating-system:
- "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
tools: composer:v2, cs2pr
- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"
- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Install locked dependencies"
if: ${{ matrix.dependencies == 'locked' }}
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "Coding Standard"
run: "vendor/bin/phpcs -q --report=checkstyle | cs2pr"
51 changes: 51 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Code coverage"
on:
pull_request:
push:
branches:
- "master"
jobs:
coverage:
name: "Code coverage"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
dependencies:
- "locked"
php-version:
- "7.4"
operating-system:
- "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"
- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Install locked dependencies"
if: ${{ matrix.dependencies == 'locked' }}
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "Code coverage"
run: |
vendor/bin/phpunit --testsuite=unit,functional --coverage-clover build/logs/clover.xml
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
php php-coveralls.phar --verbose
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
51 changes: 51 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "PHPUnit tests"
on:
pull_request:
push:
branches:
- "master"
jobs:
phpunit:
name: "PHPUnit tests"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
dependencies:
- "lowest"
- "highest"
- "locked"
php-version:
- "7.2"
- "7.3"
- "7.4"
operating-system:
- "ubuntu-latest"
- "windows-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"
- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Install locked dependencies"
if: ${{ matrix.dependencies == 'locked' }}
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "Tests"
run: "vendor/bin/phpunit --fail-on-warning"
47 changes: 47 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Static Analysis by Psalm"
on:
pull_request:
push:
branches:
- "master"
jobs:
static-analysis-psalm:
name: "Static Analysis by Psalm"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
dependencies:
- "locked"
php-version:
- "7.4"
operating-system:
- "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
tools: composer:v2, cs2pr
- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"
- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Install locked dependencies"
if: ${{ matrix.dependencies == 'locked' }}
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "psalm"
run: "vendor/bin/psalm --output-format=github --shepherd --stats"
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=7.2.0"
},
"require-dev": {
"doctrine/coding-standard": "^7.0",
"doctrine/coding-standard": "^8.2",
"phpunit/phpunit": "^8",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^3.8"
Expand Down
18 changes: 9 additions & 9 deletions src/ReservedWords.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,44 @@ public function __construct(array $reservedWords = ReservedWordsList::PHP_RESERV
* This method also returns true for words that are marked as "soft" reserved in the PHP docs and may
* become reserved in future versions of the language.
*/
public function isReserved(string $string) : bool
public function isReserved(string $string): bool
{
return array_key_exists(strtolower($string), $this->reservedWords);
}

/**
* Checks that the word cannot be used as a constant name
*/
public function isReservedConstantName(string $string, ?string $phpVersion = null) : bool
public function isReservedConstantName(string $string, ?string $phpVersion = null): bool
{
return $this->isReservedAs($string, 'constant', $phpVersion);
}

/**
* Checks that the word cannot be used as a namespace part or class/interface/trait name
*/
public function isReservedNamespaceName(string $string, ?string $phpVersion = null) : bool
public function isReservedNamespaceName(string $string, ?string $phpVersion = null): bool
{
return $this->isReservedAs($string, 'namespace', $phpVersion);
}

/**
* Checks that the word cannot be used as a function name
*/
public function isReservedFunctionName(string $string, ?string $phpVersion = null) : bool
public function isReservedFunctionName(string $string, ?string $phpVersion = null): bool
{
return $this->isReservedAs($string, 'function', $phpVersion);
}

/**
* Checks that the word cannot be used as a method name
*/
public function isReservedMethodName(string $string, ?string $phpVersion = null) : bool
public function isReservedMethodName(string $string, ?string $phpVersion = null): bool
{
return $this->isReservedAs($string, 'method', $phpVersion);
}

private function isReservedAs(string $string, string $checkKey, ?string $phpVersion = null) : bool
private function isReservedAs(string $string, string $checkKey, ?string $phpVersion = null): bool
{
if (! $this->isReserved($string)) {
return false;
Expand All @@ -101,17 +101,17 @@ private function isReservedAs(string $string, string $checkKey, ?string $phpVers
return false;
}

private function firstVersionEqualsOrHigherThanSecond(string $firstVersion, string $secondVersion) : bool
private function firstVersionEqualsOrHigherThanSecond(string $firstVersion, string $secondVersion): bool
{
return version_compare($firstVersion, $secondVersion) >= 0;
}

private function firstVersionLessThanSecond(string $firstVersion, string $secondVersion) : bool
private function firstVersionLessThanSecond(string $firstVersion, string $secondVersion): bool
{
return version_compare($firstVersion, $secondVersion) === -1;
}

private function getPhpVersion(?string $phpVersion = null) : string
private function getPhpVersion(?string $phpVersion = null): string
{
if ($phpVersion === null) {
return (string) phpversion();
Expand Down
3 changes: 2 additions & 1 deletion src/ReservedWordsLookupError.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
namespace sspat\ReservedWords;

use RuntimeException;

use function sprintf;

class ReservedWordsLookupError extends RuntimeException
{
public static function invalidPhpVersion(string $phpVersion, string $correctFormat) : self
public static function invalidPhpVersion(string $phpVersion, string $correctFormat): self
{
return new self(
sprintf('Invalid PHP version: %s, the correct format is: %s', $phpVersion, $correctFormat)
Expand Down
5 changes: 3 additions & 2 deletions tests/ReservedWordsListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\TestCase;
use sspat\ReservedWords\ReservedWords;
use sspat\ReservedWords\ReservedWordsList;

use function array_keys;
use function count;
use function is_array;
Expand All @@ -16,7 +17,7 @@

class ReservedWordsListTest extends TestCase
{
public function testReservedWordsList() : void
public function testReservedWordsList(): void
{
$errorMessage = 'Invalid reserved word configuration for %s';

Expand Down Expand Up @@ -50,7 +51,7 @@ public function testReservedWordsList() : void
/**
* @param string|bool|array<int, string> $constraint
*/
private function isValidConstraint($constraint) : bool
private function isValidConstraint($constraint): bool
{
return $constraint === false ||
(is_string($constraint) && preg_match(ReservedWords::PHP_VERSION_REGEXP, $constraint)) ||
Expand Down
Loading

0 comments on commit e42589c

Please sign in to comment.