Skip to content

Commit 6da2d42

Browse files
committed
Squashed commit of the following:
commit 9129445 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Fri Sep 29 15:46:59 2023 +0200 Update ci.yml commit 8941016 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Fri Sep 29 15:45:17 2023 +0200 Reformat commit 64a4577 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Fri Sep 29 15:32:39 2023 +0200 Add phpstan / php-cs-fixer
1 parent bd7f37b commit 6da2d42

32 files changed

+1479
-1326
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@ name: PHP Semver CI
22

33
on:
44
push:
5-
branches: [ master, v2 ]
5+
branches: [ '*' ]
66
paths-ignore:
77
- '**.md'
88
pull_request:
99
branches: [ master ]
1010

1111
jobs:
12-
analysis:
12+
test:
1313
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
1417
steps:
1518
- uses: actions/checkout@v4
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-versions }}
24+
1625
- name: Validate composer.json and composer.lock
1726
run: composer validate --strict
1827

@@ -29,24 +38,21 @@ jobs:
2938
run: |
3039
composer install --prefer-dist --no-progress --no-suggest
3140
32-
- name: Execute Code Style Check
33-
run: vendor/bin/phpcs
41+
- name: Execute tests
42+
run: vendor/bin/phpunit
3443

35-
- name: Execute Static Analysis
36-
run: vendor/bin/psalm
3744

38-
test:
45+
coverage:
46+
needs: [test]
3947
runs-on: ubuntu-latest
40-
strategy:
41-
matrix:
42-
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
4348
steps:
4449
- uses: actions/checkout@v4
4550

4651
- name: Setup PHP
4752
uses: shivammathur/setup-php@v2
4853
with:
49-
php-version: ${{ matrix.php-versions }}
54+
php-version: '7.4'
55+
extensions: xdebug
5056

5157
- name: Validate composer.json and composer.lock
5258
run: composer validate --strict
@@ -64,12 +70,13 @@ jobs:
6470
run: |
6571
composer install --prefer-dist --no-progress --no-suggest
6672
67-
- name: Execute tests
68-
run: vendor/bin/phpunit
73+
- name: Execute coverage
74+
run: vendor/bin/phpunit --coverage-clover clover.xml
6975

76+
- name: Upload coverage report
77+
run: bash <(curl -s https://codecov.io/bash)
7078

71-
coverage:
72-
needs: [test, analysis]
79+
php-cs-fixer:
7380
runs-on: ubuntu-latest
7481
steps:
7582
- uses: actions/checkout@v4
@@ -78,7 +85,7 @@ jobs:
7885
uses: shivammathur/setup-php@v2
7986
with:
8087
php-version: '7.4'
81-
extensions: xdebug
88+
ini-values: 'memory_limit=-1'
8289

8390
- name: Validate composer.json and composer.lock
8491
run: composer validate --strict
@@ -96,8 +103,35 @@ jobs:
96103
run: |
97104
composer install --prefer-dist --no-progress --no-suggest
98105
99-
- name: Execute coverage
100-
run: vendor/bin/phpunit --coverage-clover clover.xml
106+
- name: Execute Code Style Check
107+
run: vendor/bin/php-cs-fixer fix --ansi --diff --dry-run
101108

102-
- name: Upload coverage report
103-
run: bash <(curl -s https://codecov.io/bash)
109+
phpstan:
110+
runs-on: ubuntu-latest
111+
steps:
112+
- uses: actions/checkout@v4
113+
114+
- name: Setup PHP
115+
uses: shivammathur/setup-php@v2
116+
with:
117+
php-version: '7.4'
118+
ini-values: 'memory_limit=-1'
119+
120+
- name: Validate composer.json and composer.lock
121+
run: composer validate --strict
122+
123+
- name: Cache Composer packages
124+
id: composer-cache
125+
uses: actions/cache@v3
126+
with:
127+
path: vendor
128+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
129+
restore-keys: |
130+
${{ runner.os }}-php-
131+
132+
- name: Install dependencies
133+
run: |
134+
composer install --prefer-dist --no-progress --no-suggest
135+
136+
- name: Execute Static Analysis
137+
run: vendor/bin/phpstan analyse --ansi

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ composer.lock
33
.idea/
44
.phpdoc
55
*.cache
6-
76
composer.phar
8-
97
docs/
10-
118
.DS_Store

.php-cs-fixer.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__.'/src')
5+
->in(__DIR__.'/tests')
6+
;
7+
8+
$config = (new PhpCsFixer\Config())
9+
->setRules([
10+
'@PhpCsFixer' => true,
11+
'@PSR2' => true,
12+
'php_unit_internal_class' => false,
13+
'php_unit_test_class_requires_covers' => false,
14+
'global_namespace_import' => [
15+
'import_classes' => true,
16+
'import_constants' => true,
17+
'import_functions' => false,
18+
],
19+
])
20+
->setUsingCache(true)
21+
->setFinder($finder)
22+
;
23+
24+
return $config;

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^7|^8",
20-
"vimeo/psalm": "^4",
21-
"squizlabs/php_codesniffer": "^3"
20+
"phpstan/phpstan": "^1.0",
21+
"friendsofphp/php-cs-fixer": "^3.0"
2222
},
2323
"autoload": {
2424
"psr-4": {

phpcs.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src

psalm.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Constraints/Condition.php

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Condition implements VersionComparator
1515

1616
/** @var string */
1717
private $operator;
18+
1819
/** @var Version */
1920
private $version;
2021

@@ -24,6 +25,14 @@ public function __construct(string $operator, Version $version)
2425
$this->version = $version;
2526
}
2627

28+
/**
29+
* @return string the string representation of the condition
30+
*/
31+
public function __toString(): string
32+
{
33+
return $this->operator.$this->version;
34+
}
35+
2736
/**
2837
* @throws SemverException
2938
*/
@@ -32,20 +41,26 @@ public function isSatisfiedBy(Version $version): bool
3241
switch ($this->operator) {
3342
case Op::EQUAL:
3443
return $version->isEqual($this->version);
44+
3545
case Op::NOT_EQUAL:
3646
return !$version->isEqual($this->version);
47+
3748
case Op::LESS_THAN:
3849
return $version->isLessThan($this->version);
50+
3951
case Op::LESS_THAN_OR_EQUAL:
4052
case Op::LESS_THAN_OR_EQUAL2:
4153
return $version->isLessThanOrEqual($this->version);
54+
4255
case Op::GREATER_THAN:
4356
return $version->isGreaterThan($this->version);
57+
4458
case Op::GREATER_THAN_OR_EQUAL:
4559
case Op::GREATER_THAN_OR_EQUAL2:
4660
return $version->isGreaterThanOrEqual($this->version);
61+
4762
default:
48-
throw new SemverException(sprintf("Invalid operator in condition %s", (string)$this));
63+
throw new SemverException(sprintf('Invalid operator in condition %s', (string) $this));
4964
}
5065
}
5166

@@ -56,35 +71,33 @@ public function opposite(): string
5671
{
5772
switch ($this->operator) {
5873
case Op::EQUAL:
59-
return Op::NOT_EQUAL . $this->version;
74+
return Op::NOT_EQUAL.$this->version;
75+
6076
case Op::NOT_EQUAL:
61-
return Op::EQUAL . $this->version;
77+
return Op::EQUAL.$this->version;
78+
6279
case Op::LESS_THAN:
63-
return Op::GREATER_THAN_OR_EQUAL . $this->version;
80+
return Op::GREATER_THAN_OR_EQUAL.$this->version;
81+
6482
case Op::LESS_THAN_OR_EQUAL:
6583
case Op::LESS_THAN_OR_EQUAL2:
66-
return Op::GREATER_THAN . $this->version;
84+
return Op::GREATER_THAN.$this->version;
85+
6786
case Op::GREATER_THAN:
68-
return Op::LESS_THAN_OR_EQUAL . $this->version;
87+
return Op::LESS_THAN_OR_EQUAL.$this->version;
88+
6989
case Op::GREATER_THAN_OR_EQUAL:
7090
case Op::GREATER_THAN_OR_EQUAL2:
71-
return Op::LESS_THAN . $this->version;
91+
return Op::LESS_THAN.$this->version;
92+
7293
default:
73-
throw new SemverException(sprintf("Invalid operator in condition %s", (string)$this));
94+
throw new SemverException(sprintf('Invalid operator in condition %s', (string) $this));
7495
}
7596
}
7697

77-
/**
78-
* @return string The string representation of the condition.
79-
*/
80-
public function __toString(): string
81-
{
82-
return $this->operator . $this->version;
83-
}
84-
8598
public static function greaterThanMin(): Condition
8699
{
87-
return self::single("greaterThanMin", function () {
100+
return self::single('greaterThanMin', function () {
88101
return new Condition(Op::GREATER_THAN_OR_EQUAL, Version::minVersion());
89102
});
90103
}

0 commit comments

Comments
 (0)