Skip to content

Commit b72c91b

Browse files
authored
Merge pull request #303 from dotkernel/issue-300
Psalm implemented
2 parents 282932f + 148736d commit b72c91b

38 files changed

+393
-379
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
# - pull_request
3+
- push
4+
5+
name: static analysis
6+
7+
jobs:
8+
mutation:
9+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
10+
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
matrix:
15+
os:
16+
- ubuntu-latest
17+
18+
php:
19+
- "7.4"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2.3.4
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@v2
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: Static analysis
46+
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4

bin/doctrine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
use Doctrine\ORM\Tools\Console\ConsoleRunner;

bin/doctrine-migrations

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
namespace Doctrine\Migrations;
7+
8+
require __DIR__ . '/../vendor/doctrine/migrations/bin/doctrine-migrations.php';

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
"phpunit/phpunit": "^9.5.21",
7676
"roave/security-advisories": "dev-master",
7777
"squizlabs/php_codesniffer": "^3.7.1",
78-
"filp/whoops": "^2.14.5"
78+
"filp/whoops": "^2.14.5",
79+
"vimeo/psalm": "^4.29"
7980
},
8081
"autoload": {
8182
"psr-4": {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frontend\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20221014080316 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('CREATE TABLE contact_message (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', email VARCHAR(150) NOT NULL, name VARCHAR(150) NOT NULL, subject LONGTEXT NOT NULL, message LONGTEXT NOT NULL, platform LONGTEXT NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
24+
$this->addSql('CREATE TABLE user (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', identity VARCHAR(191) NOT NULL, password VARCHAR(191) NOT NULL, status ENUM(\'pending\', \'active\'), isDeleted TINYINT(1) NOT NULL, hash VARCHAR(64) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_8D93D6496A95E9C4 (identity), UNIQUE INDEX UNIQ_8D93D649D1B862B8 (hash), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
25+
$this->addSql('CREATE TABLE user_roles (userUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', roleUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', INDEX IDX_54FCD59FD73087E9 (userUuid), INDEX IDX_54FCD59F88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
26+
$this->addSql('CREATE TABLE user_avatar (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', name VARCHAR(191) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', userUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', UNIQUE INDEX UNIQ_73256912D73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
27+
$this->addSql('CREATE TABLE user_detail (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', firstName VARCHAR(191) DEFAULT NULL, lastName VARCHAR(191) DEFAULT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', userUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', UNIQUE INDEX UNIQ_4B5464AED73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
28+
$this->addSql('CREATE TABLE user_remember_me (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', rememberMeToken VARCHAR(100) NOT NULL, userAgent VARCHAR(100) NOT NULL, expireDate DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', userUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', UNIQUE INDEX UNIQ_D3E96EBD1BBB86A0 (rememberMeToken), UNIQUE INDEX UNIQ_D3E96EBDD73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
29+
$this->addSql('CREATE TABLE user_reset_password (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', expires DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', hash VARCHAR(64) NOT NULL, status VARCHAR(20) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', userUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', UNIQUE INDEX UNIQ_D21DE3BCD1B862B8 (hash), INDEX IDX_D21DE3BCD73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
30+
$this->addSql('CREATE TABLE user_role (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', name VARCHAR(30) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_2DE8C6A35E237E06 (name), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
31+
$this->addSql('ALTER TABLE user_roles ADD CONSTRAINT FK_54FCD59FD73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
32+
$this->addSql('ALTER TABLE user_roles ADD CONSTRAINT FK_54FCD59F88446210 FOREIGN KEY (roleUuid) REFERENCES user_role (uuid)');
33+
$this->addSql('ALTER TABLE user_avatar ADD CONSTRAINT FK_73256912D73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
34+
$this->addSql('ALTER TABLE user_detail ADD CONSTRAINT FK_4B5464AED73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
35+
$this->addSql('ALTER TABLE user_remember_me ADD CONSTRAINT FK_D3E96EBDD73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
36+
$this->addSql('ALTER TABLE user_reset_password ADD CONSTRAINT FK_D21DE3BCD73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
37+
}
38+
39+
public function down(Schema $schema): void
40+
{
41+
// this down() migration is auto-generated, please modify it to your needs
42+
$this->addSql('ALTER TABLE user_roles DROP FOREIGN KEY FK_54FCD59FD73087E9');
43+
$this->addSql('ALTER TABLE user_roles DROP FOREIGN KEY FK_54FCD59F88446210');
44+
$this->addSql('ALTER TABLE user_avatar DROP FOREIGN KEY FK_73256912D73087E9');
45+
$this->addSql('ALTER TABLE user_detail DROP FOREIGN KEY FK_4B5464AED73087E9');
46+
$this->addSql('ALTER TABLE user_remember_me DROP FOREIGN KEY FK_D3E96EBDD73087E9');
47+
$this->addSql('ALTER TABLE user_reset_password DROP FOREIGN KEY FK_D21DE3BCD73087E9');
48+
$this->addSql('DROP TABLE contact_message');
49+
$this->addSql('DROP TABLE user');
50+
$this->addSql('DROP TABLE user_roles');
51+
$this->addSql('DROP TABLE user_avatar');
52+
$this->addSql('DROP TABLE user_detail');
53+
$this->addSql('DROP TABLE user_remember_me');
54+
$this->addSql('DROP TABLE user_reset_password');
55+
$this->addSql('DROP TABLE user_role');
56+
}
57+
}

psalm.xml

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

src/App/src/Common/Pagination.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public static function getOffsetAndLimit(array $filters = [])
3030
}
3131

3232
return [
33-
'offset' => (int)$offset,
34-
'limit' => (int)$limit
33+
'offset' => $offset,
34+
'limit' => $limit
3535
];
3636
}
3737
}

src/App/src/Common/UuidOrderedTimeGenerator.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,31 @@
44

55
namespace Frontend\App\Common;
66

7-
use Exception;
87
use Ramsey\Uuid\Codec\OrderedTimeCodec;
9-
use Ramsey\Uuid\Uuid;
108
use Ramsey\Uuid\UuidFactory;
9+
use Ramsey\Uuid\UuidFactoryInterface;
1110
use Ramsey\Uuid\UuidInterface;
11+
use Ramsey\Uuid\Uuid;
1212

1313
/**
1414
* Class UuidOrderedTimeGenerator
1515
* @package Frontend\App\Common
1616
*/
1717
final class UuidOrderedTimeGenerator
1818
{
19-
/** @var UuidFactory $factory */
20-
private static $factory;
19+
private static UuidFactoryInterface $factory;
2120

22-
/**
23-
* @return UuidInterface
24-
*/
2521
public static function generateUuid(): UuidInterface
2622
{
27-
try {
28-
return self::getFactory()->uuid1();
29-
} catch (Exception $exception) {
30-
return null;
31-
}
23+
return self::getFactory()->uuid1();
3224
}
3325

34-
/**
35-
* @return UuidFactory
36-
*/
37-
private static function getFactory(): UuidFactory
26+
/** @psalm-suppress UndefinedInterfaceMethod */
27+
private static function getFactory(): UuidFactoryInterface
3828
{
39-
if (!self::$factory) {
40-
self::$factory = clone Uuid::getFactory();
41-
42-
$codec = new OrderedTimeCodec(
43-
self::$factory->getUuidBuilder()
44-
);
45-
46-
self::$factory->setCodec($codec);
47-
}
29+
self::$factory = clone Uuid::getFactory();
30+
$codec = new OrderedTimeCodec(self::$factory->getUuidBuilder());
31+
self::$factory->setCodec($codec);
4832

4933
return self::$factory;
5034
}

src/App/src/Middleware/RememberMeMiddleware.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8787
$user->getDetail()->getArrayCopy(),
8888
);
8989

90+
/** @psalm-suppress UndefinedInterfaceMethod */
9091
$this->authenticationService->getStorage()->write($identity);
9192
}
9293
}

src/App/src/Resolver/EntityListenerResolver.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace Frontend\App\Resolver;
66

77
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
8+
use Psr\Container\ContainerExceptionInterface;
89
use Psr\Container\ContainerInterface;
10+
use Psr\Container\NotFoundExceptionInterface;
911

1012
/**
1113
* Class EntityListenerResolver
@@ -14,7 +16,7 @@
1416
class EntityListenerResolver extends DefaultEntityListenerResolver
1517
{
1618
/** @var ContainerInterface $container */
17-
protected $container;
19+
protected ContainerInterface $container;
1820

1921
/**
2022
* EntityListenerResolver constructor.
@@ -26,10 +28,12 @@ public function __construct(ContainerInterface $container)
2628
}
2729

2830
/**
29-
* @param $className
30-
* @return mixed
31+
* @param string $className
32+
* @return object
33+
* @throws ContainerExceptionInterface
34+
* @throws NotFoundExceptionInterface
3135
*/
32-
public function resolve($className)
36+
public function resolve($className): object
3337
{
3438
return $this->container->get($className);
3539
}

0 commit comments

Comments
 (0)