Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/improve type declarations for PHP 8.1 #2218

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
db-type: [sqlite, mysql, pgsql]
prefer-lowest: ['']
include:
- php-version: '8.3'
db-type: sqlite
prefer-lowest: ''
- php-version: '8.1'
db-type: sqlite
prefer-lowest: prefer-lowest
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"phpunit/phpunit": "^9.5.19",
"sebastian/comparator": ">=1.2.3",
"cakephp/cakephp": "^5.0",
"cakephp/cakephp-codesniffer": "^4.0",
"cakephp/cakephp-codesniffer": "^5.0",
"symfony/yaml": "^3.4|^4.0|^5.0|^6.0"
},
"autoload": {
Expand Down
8 changes: 2 additions & 6 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
<ruleset name="Phinx">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>

<rule ref="CakePHP"/>

<arg value="nps"/>

<file>src/</file>
<file>tests/</file>

<exclude-pattern>*_files*</exclude-pattern>

<rule ref="CakePHP"/>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<severity>0</severity>
</rule>
</ruleset>
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,3 @@ parameters:
count: 2
path: src/Phinx/Db/Adapter/SqlServerAdapter.php

-
message: "#^Property Phinx\\\\Migration\\\\Manager\\\\Environment\\:\\:\\$adapter \\(Phinx\\\\Db\\\\Adapter\\\\AdapterInterface\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: src/Phinx/Migration/Manager/Environment.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/Phinx/Migration/Manager/Environment.php

16 changes: 7 additions & 9 deletions src/Phinx/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
use Phinx\Db\Adapter\SQLiteAdapter;
use Phinx\Util\Util;
use Psr\Container\ContainerInterface;
use ReturnTypeWillChange;
use RuntimeException;
use Symfony\Component\Yaml\Yaml;
use UnexpectedValueException;

/**
* Phinx configuration class.
*
* @package Phinx
* @author Rob Morgan
*/
class Config implements ConfigInterface, NamespaceAwareInterface
{
Expand All @@ -42,12 +40,12 @@ class Config implements ConfigInterface, NamespaceAwareInterface
/**
* @var array
*/
protected $values = [];
protected array $values = [];

/**
* @var string|null
*/
protected $configFilePath;
protected ?string $configFilePath = null;

/**
* @param array $configArray Config array
Expand Down Expand Up @@ -328,7 +326,7 @@ public function getSeedBaseClassName(bool $dropNamespace = true): string
/**
* @inheritdoc
*/
public function getTemplateFile()
public function getTemplateFile(): string|false
{
if (!isset($this->values['templates']['file'])) {
return false;
Expand All @@ -340,7 +338,7 @@ public function getTemplateFile()
/**
* @inheritdoc
*/
public function getTemplateClass()
public function getTemplateClass(): string|false
{
if (!isset($this->values['templates']['class'])) {
return false;
Expand Down Expand Up @@ -410,7 +408,7 @@ public function isVersionOrderCreationTime(): bool
/**
* @inheritdoc
*/
public function getBootstrapFile()
public function getBootstrapFile(): string|false
{
if (!isset($this->values['paths']['bootstrap'])) {
return false;
Expand Down Expand Up @@ -511,7 +509,7 @@ public function offsetSet($id, $value): void
* @throws \InvalidArgumentException
* @return mixed
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetGet($id)
{
if (!array_key_exists($id, $this->values)) {
Expand Down
9 changes: 3 additions & 6 deletions src/Phinx/Config/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

/**
* Phinx configuration interface.
*
* @package Phinx
* @author Woody Gilk
*/
interface ConfigInterface extends ArrayAccess
{
Expand Down Expand Up @@ -95,14 +92,14 @@ public function getSeedPaths(): array;
*
* @return string|false
*/
public function getTemplateFile();
public function getTemplateFile(): string|false;

/**
* Get the template class name.
*
* @return string|false
*/
public function getTemplateClass();
public function getTemplateClass(): string|false;

/**
* Get the template style to use, either change or up_down.
Expand Down Expand Up @@ -144,7 +141,7 @@ public function isVersionOrderCreationTime(): bool;
*
* @return string|false
*/
public function getBootstrapFile();
public function getBootstrapFile(): string|false;

/**
* Gets the base class name for migrations.
Expand Down
4 changes: 2 additions & 2 deletions src/Phinx/Config/FeatureFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class FeatureFlags
/**
* @var bool Should Phinx create unsigned primary keys by default?
*/
public static $unsignedPrimaryKeys = true;
public static bool $unsignedPrimaryKeys = true;
/**
* @var bool Should Phinx create columns NULL by default?
*/
public static $columnNullDefault = true;
public static bool $columnNullDefault = true;

/**
* Set the feature flags from the `feature_flags` section of the overall
Expand Down
3 changes: 0 additions & 3 deletions src/Phinx/Config/NamespaceAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

/**
* Config aware getNamespaceByPath method.
*
* @package Phinx\Config
* @author Andrey N. Mokhov
*/
interface NamespaceAwareInterface
{
Expand Down
3 changes: 0 additions & 3 deletions src/Phinx/Config/NamespaceAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

/**
* Trait implemented NamespaceAwareInterface.
*
* @package Phinx\Config
* @author Andrey N. Mokhov
*/
trait NamespaceAwareTrait
{
Expand Down
15 changes: 7 additions & 8 deletions src/Phinx/Console/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -23,8 +24,6 @@

/**
* Abstract command, contains bootstrapping info
*
* @author Rob Morgan <robbym@gmail.com>
*/
abstract class AbstractCommand extends Command
{
Expand Down Expand Up @@ -52,22 +51,22 @@ abstract class AbstractCommand extends Command
/**
* @var \Phinx\Config\ConfigInterface|null
*/
protected $config;
protected ?ConfigInterface $config = null;

/**
* @var \Phinx\Db\Adapter\AdapterInterface
*/
protected $adapter;
protected AdapterInterface $adapter;

/**
* @var \Phinx\Migration\Manager
*/
protected $manager;
protected Manager $manager;

/**
* @var int
*/
protected $verbosityLevel = OutputInterface::OUTPUT_NORMAL | OutputInterface::VERBOSITY_NORMAL;
protected int $verbosityLevel = OutputInterface::OUTPUT_NORMAL | OutputInterface::VERBOSITY_NORMAL;

/**
* Exit code for when command executes successfully
Expand Down Expand Up @@ -235,7 +234,7 @@ public function setManager(Manager $manager)
*/
public function getManager(): ?Manager
{
return $this->manager;
return $this->manager ?? null;
}

/**
Expand Down Expand Up @@ -342,7 +341,7 @@ protected function loadConfig(InputInterface $input, OutputInterface $output): v
*/
protected function loadManager(InputInterface $input, OutputInterface $output): void
{
if ($this->getManager() === null) {
if (!isset($this->manager)) {
$manager = new Manager($this->getConfig(), $input, $output);
$manager->setVerbosityLevel($this->verbosityLevel);
$container = $this->getConfig()->getContainer();
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/Breakpoint.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -19,6 +20,7 @@ class Breakpoint extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'breakpoint';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/Create.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand Down Expand Up @@ -27,6 +28,7 @@ class Create extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'create';

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Phinx/Console/Command/Init.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -23,7 +24,7 @@ class Init extends Command
/**
* @var string[]
*/
protected static $supportedFormats = [
protected static array $supportedFormats = [
AbstractCommand::FORMAT_JSON,
AbstractCommand::FORMAT_YML_ALIAS,
AbstractCommand::FORMAT_YML,
Expand All @@ -33,6 +34,7 @@ class Init extends Command
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'init';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/ListAliases.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -18,6 +19,7 @@ class ListAliases extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'list:aliases';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/Migrate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -21,6 +22,7 @@ class Migrate extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'migrate';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/Rollback.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -20,6 +21,7 @@ class Rollback extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'rollback';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/SeedCreate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand Down Expand Up @@ -26,6 +27,7 @@ class SeedCreate extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'seed:create';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/SeedRun.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -18,6 +19,7 @@ class SeedRun extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'seed:run';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/Status.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -18,6 +19,7 @@ class Status extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'status';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Phinx/Console/Command/Test.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* MIT License
Expand All @@ -21,6 +22,7 @@ class Test extends AbstractCommand
/**
* @var string|null
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
protected static $defaultName = 'test';

/**
Expand Down
Loading
Loading