Skip to content

Commit

Permalink
Merge pull request #303 from dotkernel/issue-300
Browse files Browse the repository at this point in the history
Psalm implemented
  • Loading branch information
MarioRadu authored Oct 19, 2022
2 parents 282932f + 148736d commit b72c91b
Show file tree
Hide file tree
Showing 38 changed files with 393 additions and 379 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
# - pull_request
- push

name: static analysis

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "7.4"

steps:
- name: Checkout
uses: actions/[email protected]

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
1 change: 1 addition & 0 deletions bin/doctrine
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env php
<?php

use Doctrine\ORM\Tools\Console\ConsoleRunner;
Expand Down
8 changes: 8 additions & 0 deletions bin/doctrine-migrations
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

namespace Doctrine\Migrations;

require __DIR__ . '/../vendor/doctrine/migrations/bin/doctrine-migrations.php';
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"phpunit/phpunit": "^9.5.21",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.7.1",
"filp/whoops": "^2.14.5"
"filp/whoops": "^2.14.5",
"vimeo/psalm": "^4.29"
},
"autoload": {
"psr-4": {
Expand Down
57 changes: 57 additions & 0 deletions data/doctrine/migrations/Version20221014080316.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Frontend\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221014080316 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$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');
$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');
$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');
$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');
$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');
$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');
$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');
$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');
$this->addSql('ALTER TABLE user_roles ADD CONSTRAINT FK_54FCD59FD73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
$this->addSql('ALTER TABLE user_roles ADD CONSTRAINT FK_54FCD59F88446210 FOREIGN KEY (roleUuid) REFERENCES user_role (uuid)');
$this->addSql('ALTER TABLE user_avatar ADD CONSTRAINT FK_73256912D73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
$this->addSql('ALTER TABLE user_detail ADD CONSTRAINT FK_4B5464AED73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
$this->addSql('ALTER TABLE user_remember_me ADD CONSTRAINT FK_D3E96EBDD73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
$this->addSql('ALTER TABLE user_reset_password ADD CONSTRAINT FK_D21DE3BCD73087E9 FOREIGN KEY (userUuid) REFERENCES user (uuid)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE user_roles DROP FOREIGN KEY FK_54FCD59FD73087E9');
$this->addSql('ALTER TABLE user_roles DROP FOREIGN KEY FK_54FCD59F88446210');
$this->addSql('ALTER TABLE user_avatar DROP FOREIGN KEY FK_73256912D73087E9');
$this->addSql('ALTER TABLE user_detail DROP FOREIGN KEY FK_4B5464AED73087E9');
$this->addSql('ALTER TABLE user_remember_me DROP FOREIGN KEY FK_D3E96EBDD73087E9');
$this->addSql('ALTER TABLE user_reset_password DROP FOREIGN KEY FK_D21DE3BCD73087E9');
$this->addSql('DROP TABLE contact_message');
$this->addSql('DROP TABLE user');
$this->addSql('DROP TABLE user_roles');
$this->addSql('DROP TABLE user_avatar');
$this->addSql('DROP TABLE user_detail');
$this->addSql('DROP TABLE user_remember_me');
$this->addSql('DROP TABLE user_reset_password');
$this->addSql('DROP TABLE user_role');
}
}
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
4 changes: 2 additions & 2 deletions src/App/src/Common/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static function getOffsetAndLimit(array $filters = [])
}

return [
'offset' => (int)$offset,
'limit' => (int)$limit
'offset' => $offset,
'limit' => $limit
];
}
}
34 changes: 9 additions & 25 deletions src/App/src/Common/UuidOrderedTimeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,31 @@

namespace Frontend\App\Common;

use Exception;
use Ramsey\Uuid\Codec\OrderedTimeCodec;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
use Ramsey\Uuid\UuidFactoryInterface;
use Ramsey\Uuid\UuidInterface;
use Ramsey\Uuid\Uuid;

/**
* Class UuidOrderedTimeGenerator
* @package Frontend\App\Common
*/
final class UuidOrderedTimeGenerator
{
/** @var UuidFactory $factory */
private static $factory;
private static UuidFactoryInterface $factory;

/**
* @return UuidInterface
*/
public static function generateUuid(): UuidInterface
{
try {
return self::getFactory()->uuid1();
} catch (Exception $exception) {
return null;
}
return self::getFactory()->uuid1();
}

/**
* @return UuidFactory
*/
private static function getFactory(): UuidFactory
/** @psalm-suppress UndefinedInterfaceMethod */
private static function getFactory(): UuidFactoryInterface
{
if (!self::$factory) {
self::$factory = clone Uuid::getFactory();

$codec = new OrderedTimeCodec(
self::$factory->getUuidBuilder()
);

self::$factory->setCodec($codec);
}
self::$factory = clone Uuid::getFactory();
$codec = new OrderedTimeCodec(self::$factory->getUuidBuilder());
self::$factory->setCodec($codec);

return self::$factory;
}
Expand Down
1 change: 1 addition & 0 deletions src/App/src/Middleware/RememberMeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$user->getDetail()->getArrayCopy(),
);

/** @psalm-suppress UndefinedInterfaceMethod */
$this->authenticationService->getStorage()->write($identity);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/App/src/Resolver/EntityListenerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Frontend\App\Resolver;

use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* Class EntityListenerResolver
Expand All @@ -14,7 +16,7 @@
class EntityListenerResolver extends DefaultEntityListenerResolver
{
/** @var ContainerInterface $container */
protected $container;
protected ContainerInterface $container;

/**
* EntityListenerResolver constructor.
Expand All @@ -26,10 +28,12 @@ public function __construct(ContainerInterface $container)
}

/**
* @param $className
* @return mixed
* @param string $className
* @return object
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function resolve($className)
public function resolve($className): object
{
return $this->container->get($className);
}
Expand Down
4 changes: 3 additions & 1 deletion src/App/src/Service/RecaptchaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function setResponse(string $response): self
*/
public function isValid(): bool
{
if (! isset($this->response)) {
if (empty($this->response)) {
throw new InvalidArgumentException('Recaptcha response not initialized.');
}

Expand All @@ -64,6 +64,8 @@ public function isValid(): bool
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));

$response = curl_exec($curl);

/** @psalm-suppress InvalidScalarArgument */
$response = json_decode($response, true);
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

Expand Down
19 changes: 5 additions & 14 deletions src/Contact/src/Form/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
use Laminas\Form\Element\Text;
use Laminas\Form\Element\Textarea;
use Laminas\Form\Form;
use Laminas\InputFilter\InputFilter;
use Laminas\InputFilter\InputFilterInterface;

/**
* Class ContactForm
* @package Frontend\Contact\Form
*/
class ContactForm extends Form
{
/** @var InputFilter $inputFilter */
protected $inputFilter;
/** @var InputFilterInterface $inputFilter */
protected InputFilterInterface $inputFilter;

/**
* ContactForm constructor.
Expand Down Expand Up @@ -84,21 +84,12 @@ public function init()
],
'type' => Textarea::class,
]);

// $this->add([
// 'name' => 'submit',
// 'type' => 'submit',
// 'attributes' => [
// 'type' => 'submit',
// 'value' => 'Send message'
// ]
// ], ['priority' => -105]);
}

/**
* @return null|InputFilter|\Laminas\InputFilter\InputFilterInterface
* @return InputFilterInterface
*/
public function getInputFilter(): \Laminas\InputFilter\InputFilterInterface
public function getInputFilter(): InputFilterInterface
{
return $this->inputFilter;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Plugin/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Frontend\Plugin;

use Frontend\Plugin\Factory\FlashMessengerPluginFactory;
use Frontend\Plugin\Factory\FormsPluginFactory;
use Frontend\Plugin\Factory\PluginManagerAwareInitializer;
use Frontend\Plugin\Factory\PluginManagerFactory;
Expand All @@ -26,7 +25,6 @@ public function __invoke(): array
'dot_controller' => [
'plugin_manager' => [
'factories' => [
'messenger' => FlashMessengerPluginFactory::class,
'forms' => FormsPluginFactory::class,
],
],
Expand Down
Loading

0 comments on commit b72c91b

Please sign in to comment.