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

#42: PHP 8.1 compatibility fixes #44

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions .driver/commands.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
commands:
pipeline:
class: \Driver\Pipeline\Command
connect:
class: \Driver\Engines\MySql
check-filesystem:
Expand Down
1 change: 1 addition & 0 deletions .driver/connections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ connections:
instance-type: db.t3.medium
engine: MySQL
storage-type: gp2
region: us-east-2

# TODO: fix merging so that the other keys overwrite this.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.lock
/vagrant/
.DS_Store
sample/
.phpunit.result.cache
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
"require": {
"php": "^7.4|^8.0",
"ext-pdo": "*",
"php-di/php-di": "^6.0",
"aws/aws-sdk-php": "^3.19",
"symfony/yaml": ">=2.3",
"ericpoe/haystack": "^1.0",
"guzzlehttp/guzzle": "^6.2|^7.0",
"php-di/php-di": "^6.0",
"psr/log": "^1.0",
"symfony/console": "^4.4",
"symfony/event-dispatcher": "^4.0"
"symfony/event-dispatcher": "^4.0",
"symfony/yaml": ">=2.3"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.7",
"phpunit/phpunit": "^5.6",
"phpunit/dbunit": "^2.0"
"phpunit/phpunit": "^9.5",
"slevomat/coding-standard": "^8.5",
"squizlabs/php_codesniffer": "^3.7"
},
"bin": ["bin/driver"],
"autoload": {
Expand Down
40 changes: 40 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<ruleset name="SwiftOtter.Driver">
<file>src</file>
<rule ref="PSR12"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<severity>7</severity>
<type>warning</type>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<severity>7</severity>
<type>warning</type>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<severity>7</severity>
<type>warning</type>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint">
<severity>7</severity>
<type>warning</type>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<severity>7</severity>
<type>warning</type>
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2"/>
<property name="newlinesCountAfterDeclare" value="2"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName">
<severity>7</severity>
<type>warning</type>
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore" />
</rule>
<rule ref="Squiz.NamingConventions.ValidFunctionName">
<severity>7</severity>
<type>warning</type>
<exclude name="Squiz.NamingConventions.ValidFunctionName.PrivateNoUnderscore" />
</rule>
</ruleset>
9 changes: 4 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xml:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="phpunit.bootstrap.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="phpunit.bootstrap.php">
<testsuites>
<testsuite name="Unit Tests">
<directory>src/Tests/Unit/**</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
27 changes: 4 additions & 23 deletions src/Commands/CleanupInterface.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<?php
/**
* SwiftOtter_Base is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SwiftOtter_Base is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with SwiftOtter_Base. If not, see <http://www.gnu.org/licenses/>.
*
* @author Joseph Maxwell
* @copyright SwiftOtter Studios, 11/5/16
* @package default
**/

declare(strict_types=1);

namespace Driver\Commands;

Expand All @@ -24,9 +9,5 @@

interface CleanupInterface
{
/**
* @param TransportInterface $transport
* @return TransportInterface
*/
public function cleanup(TransportInterface $transport, EnvironmentInterface $environment);
}
public function cleanup(TransportInterface $transport, EnvironmentInterface $environment): TransportInterface;
}
28 changes: 5 additions & 23 deletions src/Commands/CommandInterface.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<?php
/**
* SwiftOtter_Base is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SwiftOtter_Base is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with SwiftOtter_Base. If not, see <http://www.gnu.org/licenses/>.
*
* @author Joseph Maxwell
* @copyright SwiftOtter Studios, 11/5/16
* @package default
**/

declare(strict_types=1);

namespace Driver\Commands;

Expand All @@ -24,11 +9,8 @@

interface CommandInterface
{
/**
* @param TransportInterface $transport
* @return TransportInterface
*/
public function go(TransportInterface $transport, EnvironmentInterface $environment);
public function go(TransportInterface $transport, EnvironmentInterface $environment): TransportInterface;

public function getProperties();
// phpcs:ignore SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
public function getProperties(): array;
}
32 changes: 10 additions & 22 deletions src/Commands/Environment/Setup.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<?php
/**
* SwiftOtter_Base is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SwiftOtter_Base is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with SwiftOtter_Base. If not, see <http://www.gnu.org/licenses/>.
*
* @author Joseph Maxwell
* @copyright SwiftOtter Studios, 12/10/16
* @package default
**/

declare(strict_types=1);

namespace Driver\Commands\Environment;

Expand All @@ -26,22 +11,25 @@

class Setup extends Command implements CommandInterface
{
private $properties;
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification
private array $properties;

public function __construct($properties = [])
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
public function __construct(array $properties = [])
{
$this->properties = $properties;
parent::__construct('environment-configuration');
}

public function getProperties()
// phpcs:ignore SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
public function getProperties(): array
{
return $this->properties;
}

public function go(TransportInterface $transport, EnvironmentInterface $environment)
public function go(TransportInterface $transport, EnvironmentInterface $environment): TransportInterface
{
// @todo Check this!
return $transport->withEnvironment($environment);
}

}
25 changes: 3 additions & 22 deletions src/Commands/ErrorInterface.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<?php
/**
* SwiftOtter_Base is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SwiftOtter_Base is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with SwiftOtter_Base. If not, see <http://www.gnu.org/licenses/>.
*
* @author Joseph Maxwell
* @copyright SwiftOtter Studios, 11/5/16
* @package default
**/

declare(strict_types=1);

namespace Driver\Commands;

Expand All @@ -24,9 +9,5 @@

interface ErrorInterface
{
/**
* @param TransportInterface $transport
* @return TransportInterface
*/
public function error(TransportInterface $transport, EnvironmentInterface $environment);
public function error(TransportInterface $transport, EnvironmentInterface $environment): TransportInterface;
}
56 changes: 22 additions & 34 deletions src/Commands/Factory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<?php
/**
* SwiftOtter_Base is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SwiftOtter_Base is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with SwiftOtter_Base. If not, see <http://www.gnu.org/licenses/>.
*
* @author Joseph Maxwell
* @copyright SwiftOtter Studios, 11/5/16
* @package default
**/

declare(strict_types=1);

namespace Driver\Commands;

Expand All @@ -24,44 +9,45 @@

class Factory
{
private $configuration;
private $container;
private $substitutions;
private Configuration $configuration;
private Container $container;
/** @var array<string, string>|null */
private ?array $substitutions = null;

public function __construct(Configuration $configuration, Container $container)
{
$this->configuration = $configuration;
$this->container = $container;
}

/**
* @param $name
* @return CommandInterface
*/
public function create($name, $properties = [])
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
public function create(string $name, array $properties = []): CommandInterface
{
$className = $this->getClassName($name);
return $this->container->make($className, ['properties' => $properties]);
}

private function getClassName($name)
private function getClassName(string $name): string
{
$class = $this->runSubstitutions($this->configuration->getNode("commands/{$name}/class"));
$class = $this->runSubstitutions((string)$this->configuration->getNode("commands/{$name}/class"));
if (class_exists($class) && in_array(CommandInterface::class, class_implements($class))) {
return $class;
} else {
throw new \Exception("{$name} doesn't exist or it doesn't implement the type " . CommandInterface::class . ".");
var_dump($class);
throw new \Exception(
"{$name} doesn't exist or it doesn't implement the type " . CommandInterface::class . "."
);
}
}

private function runSubstitutions($name)
private function runSubstitutions(string $name): string
{
$substitutions = $this->getSubstitutions();
preg_match_all("/%(.+)%/U", $name, $matches);

if (count($matches) > 1) {
$replacements = array_reduce($matches[1], function($carry, $name) use ($substitutions) {
$carry['%'.$name.'%'] = $substitutions[$name];
$replacements = array_reduce($matches[1], function ($carry, $name) use ($substitutions) {
$carry['%' . $name . '%'] = $substitutions[$name];
return $carry;
}, []);

Expand All @@ -71,7 +57,10 @@ private function runSubstitutions($name)
}
}

private function getSubstitutions()
/**
* @return string[]
*/
private function getSubstitutions(): array
{
if (!$this->substitutions) {
$databaseEngine = $this->configuration->getNode('connections/database');
Expand All @@ -83,9 +72,8 @@ private function getSubstitutions()
'engine' => $this->configuration->getNode("engines/{$databaseEngine}/class-name")
];
$this->substitutions = $substitutions;

}

return $this->substitutions;
}
}
}
Loading