Skip to content

Commit be7a5e7

Browse files
author
Andrei Onita
committed
implemented psalm, cs-check, static analysis & fixed psalm errors
1 parent 6cf2d35 commit be7a5e7

21 files changed

Lines changed: 300 additions & 157 deletions

.github/workflows/cs-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
- push
3+
4+
name: Run phpcs checks
5+
6+
jobs:
7+
mutation:
8+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Install PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: "${{ matrix.php }}"
29+
tools: composer:v2, cs2pr
30+
coverage: none
31+
32+
- name: Determine composer cache directory
33+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
34+
35+
- name: Cache dependencies installed with composer
36+
uses: actions/cache@v3
37+
with:
38+
path: ${{ env.COMPOSER_CACHE_DIR }}
39+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
40+
restore-keys: |
41+
php${{ matrix.php }}-composer-
42+
- name: Install dependencies with composer
43+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
44+
45+
- name: Run phpcs checks
46+
run: vendor/bin/phpcs
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
- push
3+
4+
name: Run static analysis
5+
6+
jobs:
7+
mutation:
8+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Install PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: "${{ matrix.php }}"
29+
tools: composer:v2, cs2pr
30+
coverage: none
31+
32+
- name: Determine composer cache directory
33+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
34+
35+
- name: Cache dependencies installed with composer
36+
uses: actions/cache@v3
37+
with:
38+
path: ${{ env.COMPOSER_CACHE_DIR }}
39+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
40+
restore-keys: |
41+
php${{ matrix.php }}-composer-
42+
- name: Install dependencies with composer
43+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
44+
45+
- name: Run static analysis
46+
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4

.github/workflows/unit-test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
on:
2+
- push
3+
4+
name: Run PHPUnit tests
5+
6+
jobs:
7+
mutation:
8+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Install PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: "${{ matrix.php }}"
29+
tools: composer:v2, cs2pr
30+
coverage: none
31+
32+
- name: Determine composer cache directory
33+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
34+
35+
- name: Cache dependencies installed with composer
36+
uses: actions/cache@v3
37+
with:
38+
path: ${{ env.COMPOSER_CACHE_DIR }}
39+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
40+
restore-keys: |
41+
php${{ matrix.php }}-composer-
42+
43+
- name: Install dependencies with composer
44+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
45+
46+
- name: Run PHPUnit tests
47+
run: vendor/bin/phpunit --colors=always

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
clover.xml
22
coveralls-upload.json
3-
phpunit.xml
43

54
# Created by .ignore support plugin (hsz.mobi)
65
### JetBrains template
@@ -38,3 +37,4 @@ composer.phar
3837
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
3938
composer.lock
4039
.phpunit.result.cache
40+
.phpcs-cache

composer.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
"service-manager"
2121
],
2222
"require": {
23-
"php": "~7.4.0 || ~8.0.0 || ~8.1.0",
23+
"php": "~8.1.0",
2424
"laminas/laminas-servicemanager": "^3.10",
2525
"doctrine/annotations": "^1.13",
2626
"doctrine/cache": "^1.13",
2727
"doctrine/orm" : "^2.11"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^9.5",
31-
"squizlabs/php_codesniffer": "^3.6"
30+
"phpunit/phpunit": "^10.2",
31+
"squizlabs/php_codesniffer": "^3.6",
32+
"vimeo/psalm": "^5.13",
33+
"laminas/laminas-coding-standard": "^2.5"
3234
},
3335
"autoload": {
3436
"psr-4": {
@@ -40,8 +42,24 @@
4042
"DotTest\\AnnotatedServices\\": "tests"
4143
}
4244
},
45+
"scripts": {
46+
"check": [
47+
"@cs-check",
48+
"@test"
49+
],
50+
"cs-check": "phpcs",
51+
"cs-fix": "phpcbf",
52+
"test": "phpunit --colors=always",
53+
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
54+
"static-analysis": "psalm --shepherd --stats"
55+
},
4356
"suggest": {
4457
"doctrine/cache": "To cache the result of processing the annotations and speed-up your application.",
4558
"doctrine/orm": "To be able to inject doctrine repositories."
59+
},
60+
"config": {
61+
"allow-plugins": {
62+
"dealerdirect/phpcodesniffer-composer-installer": true
63+
}
4664
}
4765
}

phpcs.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg name="extensions" value="php"/>
9+
<arg name="parallel" value="80"/>
10+
11+
<!-- Show progress -->
12+
<arg value="p"/>
13+
14+
<!-- Paths to check -->
15+
<file>src</file>
16+
<file>tests</file>
17+
18+
<!-- Include all rules from the Laminas Coding Standard -->
19+
<rule ref="LaminasCodingStandard"/>
20+
</ruleset>

phpunit.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="./vendor/autoload.php" colors="true">
3+
<testsuites>
4+
<testsuite name="dot-user-agent-sniffer Test Suite">
5+
<directory>./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage/>
9+
<source>
10+
<include>
11+
<directory suffix=".php">./src</directory>
12+
</include>
13+
</source>
14+
</phpunit>

psalm.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
findUnusedCode="false"
6+
findUnusedBaselineEntry="true"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<ignoreFiles>
14+
<directory name="vendor" />
15+
</ignoreFiles>
16+
</projectFiles>
17+
</psalm>

src/Annotation/Entity.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace Dot\AnnotatedServices\Annotation;
66

77
use Doctrine\Common\Annotations\Annotation;
8-
use Doctrine\Common\Annotations\Annotation\Target;
9-
use Doctrine\Common\Annotations\Annotation\Required;
108
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
9+
use Doctrine\Common\Annotations\Annotation\Required;
10+
use Doctrine\Common\Annotations\Annotation\Target;
1111

1212
/**
13-
* Class Entity
14-
* @package Dot\AnnotatedServices\Annotation
15-
*
1613
* @Annotation
1714
* @NamedArgumentConstructor
1815
* @Target({"CLASS"})
@@ -22,18 +19,11 @@ class Entity
2219
/** @Required */
2320
private string $name;
2421

25-
/**
26-
* Entity constructor.
27-
* @param string $name
28-
*/
2922
public function __construct(string $name)
3023
{
3124
$this->name = $name;
3225
}
3326

34-
/**
35-
* @return string
36-
*/
3727
public function getName(): string
3828
{
3929
return $this->name;

src/Annotation/Inject.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
<?php
2+
23
/**
34
* @see https://github.com/dotkernel/dot-annotated-services/ for the canonical source repository
4-
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
5-
* @license https://github.com/dotkernel/dot-annotated-services/blob/master/LICENSE.md MIT License
65
*/
76

8-
declare(strict_types = 1);
7+
declare(strict_types=1);
98

109
namespace Dot\AnnotatedServices\Annotation;
1110

1211
use Doctrine\Common\Annotations\Annotation;
1312
use Doctrine\Common\Annotations\Annotation\Target;
1413

1514
/**
16-
* Class Inject
17-
* @package Dot\AnnotatedServiced\Annotation
1815
* @Annotation
1916
* @Target({"METHOD"})
2017
*/
@@ -24,12 +21,11 @@ class Inject
2421
private $services = [];
2522

2623
/**
27-
* Inject constructor.
2824
* @param array $values
2925
*/
3026
public function __construct(array $values)
3127
{
32-
$this->services = isset($values['value']) ? $values['value'] : [];
28+
$this->services = $values['value'] ?? [];
3329
}
3430

3531
/**

0 commit comments

Comments
 (0)