Skip to content

Commit

Permalink
Merge pull request #23 from Fabricio872/feature/upgrade-packages
Browse files Browse the repository at this point in the history
fixed deprecations dropped support for php older than 8.1
  • Loading branch information
Fabricio872 authored Feb 16, 2023
2 parents 28285cd + e13cc18 commit 098bb55
Show file tree
Hide file tree
Showing 30 changed files with 310 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-composer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: Run psr-12 test
run: composer run-script test-psr
run: composer run-script cs
27 changes: 22 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@
}
],
"require": {
"php": "^7.3|^8.0",
"php": "^8.1",
"doctrine/annotations": "^1.13|^2.0",
"doctrine/orm": "^2.9",
"symfony/config": "^4.4|^5|^6.0",
"symfony/console": "^4.4|^5|^6.0",
"symfony/dependency-injection": "^4.4|^5|^6.0",
"symfony/dotenv": "^4.4|^5|^6.0",
"symfony/http-kernel": "^4.4|^5|^6.0",
"symfony/security-bundle": "^4.4|^5|^6.0",
"symfony/serializer": "^4.4|^5|^6.0",
"symfony/validator": "^4.4|^5|^6.0"
},
"require-dev": {
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9",
"rector/rector": "^0.15.16",
"symfony/phpunit-bridge": "^4.4|^5|^6.0",
"symplify/easy-coding-standard": "^9.4"
"symplify/easy-coding-standard": "^11.2.8"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -33,7 +37,8 @@
},
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true
}
},
"autoload": {
Expand All @@ -47,7 +52,19 @@
}
},
"scripts": {
"test-psr": "vendor/bin/ecs check src",
"fix-psr": "vendor/bin/ecs check src --fix"
"cs": [
"@ecs",
"@rector",
"@phpstan"
],
"cs-fix": [
"@ecs-fix",
"@rector-fix"
],
"ecs": "vendor/bin/ecs check",
"ecs-fix": "vendor/bin/ecs check --fix",
"rector": "vendor/bin/rector process --dry-run",
"rector-fix": "vendor/bin/rector process",
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon"
}
}
28 changes: 15 additions & 13 deletions ecs.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
declare(strict_types=1);

use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/ecs.php',
__DIR__ . '/rector.php',
]);

$services = $containerConfigurator->services();
$services->set(ArraySyntaxFixer::class)
->call('configure', [[
'syntax' => 'short',
]]);
// B. standalone rule
$ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [
'syntax' => 'short',
]);

$containerConfigurator->import(SetList::ARRAY);
$containerConfigurator->import(SetList::PSR_12);
$ecsConfig->sets([
SetList::SPACES,
SetList::PSR_12,
SetList::CLEAN_CODE,
SetList::STRICT,
]);
};
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 5
paths:
- src
excludePaths:
- src/DependencyInjection/Configuration
34 changes: 34 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Symfony\Set\SensiolabsSetList;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/ecs.php',
__DIR__ . '/rector.php',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
]);

$rectorConfig->sets([
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
SensiolabsSetList::FRAMEWORK_EXTRA_61,
]);

$rectorConfig->importNames();
};
16 changes: 9 additions & 7 deletions src/Annotations/RegisterCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Fabricio872\RegisterCommand\Annotations;

use Attribute;
Expand All @@ -22,7 +24,7 @@ class RegisterCommand

/**
* Question that has to be asked user
* @var string
* @var ?string
*/
public $question;

Expand Down Expand Up @@ -78,14 +80,14 @@ class RegisterCommand
public function __construct(
?string $field = null,
?string $question = null,
?array $options = null,
bool $userIdentifier = false,
?bool $valueBoolean = null,
?array $options = null,
bool $userIdentifier = false,
?bool $valueBoolean = null,
?string $valueString = null,
?string $valuePassword = null,
?array $valueArray = null,
?int $valueInt = null,
?float $valueFloat = null,
?array $valueArray = null,
?int $valueInt = null,
?float $valueFloat = null,
?string $valueDateTime = null
) {
$this->field = $field;
Expand Down
42 changes: 21 additions & 21 deletions src/Command/AbstractList.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

declare(strict_types=1);

namespace Fabricio872\RegisterCommand\Command;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\Reader;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -19,30 +22,37 @@ abstract class AbstractList extends Command
{
/** @var string */
protected $userClassName;
/** @var int */
private $tableLimit;
/** @var int */
private $maxColWidth;

/** @var InputInterface */
protected $input;

/** @var OutputInterface */
protected $output;

/** @var SymfonyStyle */
protected $io;

/** @var EntityManagerInterface */
protected $em;

/** @var int */
protected $colWidth;

/** @var int */
protected $totalUsers;

/** @var int */
protected $limitUsers;

/** @var int */
protected $currentPage = 0;

/** @var UserPasswordHasherInterface */
protected $passwordEncoder;

/** @var Reader */
protected $reader;

/** @var ValidatorInterface */
protected $validator;

Expand All @@ -54,15 +64,13 @@ abstract class AbstractList extends Command
*/
public function __construct(
string $userClassName,
int $tableLimit,
int $maxColWidth,
private readonly int $tableLimit,
private readonly int $maxColWidth,
EntityManagerInterface $em,
UserPasswordHasherInterface $passwordEncoder,
ValidatorInterface $validator
) {
$this->userClassName = $userClassName;
$this->tableLimit = $tableLimit;
$this->maxColWidth = $maxColWidth;
$this->em = $em;
$this->passwordEncoder = $passwordEncoder;
$this->reader = new AnnotationReader();
Expand All @@ -82,14 +90,13 @@ protected function configure()
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws \Exception
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->input = $input;
$this->output = $output;
$this->io = new SymfonyStyle($this->input, $this->output);
/** @var int $colWidth */
$this->colWidth = $this->input->getOption('col-width');

$this->totalUsers = $this->em
Expand All @@ -98,38 +105,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->limitUsers = $this->input->getOption('limit');

if ($this->totalUsers == 0) {
if ($this->totalUsers === 0) {
$this->io->warning("User Table is empty");
return 0;
}

$userClass = new $this->userClassName();
if (!$userClass instanceof UserInterface) {
throw new \Exception("Provided user must implement " . UserInterface::class);
if (! $userClass instanceof UserInterface) {
throw new Exception("Provided user must implement " . UserInterface::class);
}

return $this->draw(null);
}

/**
* @return string
*/
protected function askPage(): string
{
return $this->io->ask('page', ($this->currentPage < $this->getTotalPages()) ? $this->currentPage + 1 : 'q');
}

/**
* @return false|float
*/
protected function getTotalPages()
protected function getTotalPages(): false|float
{
return ceil($this->totalUsers / $this->limitUsers);
}

/**
* @param int $page
* @return int
*/
abstract protected function draw(?int $page): int;
}
13 changes: 8 additions & 5 deletions src/Command/UserListCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Fabricio872\RegisterCommand\Command;

use Fabricio872\RegisterCommand\Services\ArrayToTable;
Expand All @@ -11,9 +13,11 @@
class UserListCommand extends AbstractList
{
protected static $defaultName = 'user:list';

protected static $defaultDescription = 'List all existing users';

/** @var array|object[] */
private $userList;
private ?array $userList = null;

protected function configure()
{
Expand Down Expand Up @@ -67,15 +71,14 @@ protected function draw(?int $page): int

/**
* @param $page
* @return int|null
*/
protected function getPage($page): ?int
{
if (strtolower($page) == 'q') {
if (strtolower((string) $page) === 'q') {
$this->io->writeln('Bye (=◉ᆽ◉=)');
return null;
}
if (strtolower($page) == 'e') {
if (strtolower((string) $page) === 'e') {
/** @var UserEditorInterface $userEditor */
$userEditor = new UserEditor(
$this->input,
Expand All @@ -88,7 +91,7 @@ protected function getPage($page): ?int
$userEditor->drawEdiTable();
return $this->getPage($this->askPage());
}
if (!is_numeric($page)) {
if (! is_numeric($page)) {
$this->io->writeln('Bad input');
return $this->getPage($this->askPage());
}
Expand Down
Loading

0 comments on commit 098bb55

Please sign in to comment.