Skip to content

Commit

Permalink
Psalm fixes, moved from phpunit to simple-phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
devnix committed Nov 24, 2020
1 parent adfce25 commit 007b0cd
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 60 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
strategy:
matrix:
php-version:
- '5.3'
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'
Expand All @@ -26,18 +23,6 @@ jobs:
allowed_to_fail: [false]
variant: [normal]
include:
- php-version: '5.3'
dependencies: lowest
allowed_to_fail: false
variant: normal
- php-version: '5.4'
dependencies: lowest
allowed_to_fail: false
variant: normal
- php-version: '5.5'
dependencies: lowest
allowed_to_fail: false
variant: normal
- php-version: '5.6'
dependencies: lowest
allowed_to_fail: false
Expand Down Expand Up @@ -99,4 +84,4 @@ jobs:
run: composer update --prefer-dist --no-progress --no-interaction --prefer-stable

- name: Run Tests
run: vendor/bin/phpunit
run: vendor/bin/simple-phpunit
67 changes: 36 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
{
"name": "avaibooksports/redsys-messages",
"keywords": ["tpv", "gateway", "redsys", "sermepa", "servired", "messages"],
"description": "Redsys/Sermepa/Servired gateway message lists",
"license": "MIT",
"authors": [
{
"name": "AvaiBook Sports",
"email": "desarrollo@avaibooksports.com",
"homepage": "https://www.avaibooksports.com"
},
{
"name": "Pablo Largo",
"email": "devnix.code@gmail.com"
},
{
"name": "Lito",
"email": "lito@eordes.com"
}
],
"require": {
"php": ">=5.3"
"name": "avaibooksports/redsys-messages",
"keywords": ["tpv", "gateway", "redsys", "sermepa", "servired", "messages"],
"description": "Redsys/Sermepa/Servired gateway message lists",
"license": "MIT",
"authors": [
{
"name": "AvaiBook Sports",
"email": "desarrollo@avaibooksports.com",
"homepage": "https://www.avaibooksports.com"
},
{
"name": "Pablo Largo",
"email": "devnix.code@gmail.com"
},
{
"name": "Lito",
"email": "lito@eordes.com"
}
],
"require": {
"php": ">=5.6"
},
"suggest": {
"league/omnipay": "A payment processing library compatible with multiple payment gateways",
"avaibooksports/omnipay-redsys": "An Omnipay driver for Redsys"
"avaibooksports/omnipay-redsys": "An Omnipay driver for Redsys",
"vimeo/psalm": "If you are going to contribute to this package"
},
"autoload": {
"psr-4": {
"AvaiBookSports\\Component\\RedsysMessages\\": "src"
}
"autoload": {
"psr-4": {
"AvaiBookSports\\Component\\RedsysMessages\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"vimeo/psalm": "^3.16",
"friendsofphp/php-cs-fixer": "^2.16"
}
"autoload-dev": {
"psr-4": {
"AvaiBookSports\\Component\\RedsysMessages\\" : "tests/"
}
},
"require-dev": {
"symfony/phpunit-bridge": "^5.1",
"friendsofphp/php-cs-fixer": "^2.16"
}
}
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true">
convertWarningsToExceptions = "true"
bootstrap ="vendor/autoload.php">
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
Expand Down
4 changes: 2 additions & 2 deletions src/Catalog/English.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class English implements CatalogInterface
{
/**
* @var array
* @var string[]
*/
private $dsResponseMessages = [
'0101' => 'Expired card',
Expand Down Expand Up @@ -63,7 +63,7 @@ public static function getIso639Alpha3()
/**
* {@inheritdoc}
*/
public function getDsResponseMessage(string $code)
public function getDsResponseMessage($code)
{
if (array_key_exists($code, $this->dsResponseMessages)) {
return $this->dsResponseMessages[$code];
Expand Down
4 changes: 2 additions & 2 deletions src/Catalog/Spanish.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Spanish implements CatalogInterface
{
/**
* @var array
* @var string[]
*/
private $dsResponseMessages = [
'0101' => 'Tarjeta caducada',
Expand Down Expand Up @@ -63,7 +63,7 @@ public static function getIso639Alpha3()
/**
* {@inheritdoc}
*/
public function getDsResponseMessage(string $code)
public function getDsResponseMessage($code)
{
if (array_key_exists($code, $this->dsResponseMessages)) {
return $this->dsResponseMessages[$code];
Expand Down
4 changes: 3 additions & 1 deletion src/CatalogInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public static function getIso639Alpha2();
public static function getIso639Alpha3();

/**
* @param string $code
*
* @return string|null Friendly error message for the customer or null if not found
*/
public function getDsResponseMessage(string $code);
public function getDsResponseMessage($code);
}
2 changes: 1 addition & 1 deletion src/Exception/RedsysMessageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace AvaiBookSports\Component\RedsysMessages\Exception;

interface RedsysMessageException extends \Throwable
interface RedsysMessageException
{
}
19 changes: 15 additions & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ public function __construct(CatalogLoaderInterface $loader)
$this->setLoader($loader);
}

public function setLoader(CatalogLoaderInterface $loader)
/**
* @return self
*/
final public function setLoader(CatalogLoaderInterface $loader)
{
$this->checkCatalogs($loader->getCatalogs());
$this->assertCatalogs($loader->getCatalogs());

$this->loader = $loader;

return $this;
}

/**
* @param string[] $catalogs
*
* @return self
*
* @throws RuntimeException if a catalog is not found or doesn't implement CatalogInterface
*/
private function checkCatalogs(array $catalogs)
private function assertCatalogs(array $catalogs)
{
foreach ($catalogs as $catalog) {
if (!class_exists($catalog)) {
Expand All @@ -41,14 +48,18 @@ private function checkCatalogs(array $catalogs)
throw new RuntimeException(sprintf('Class "%s" must implement %s', $catalog, CatalogInterface::class));
}
}

return $this;
}

/**
* Get a message catalog by language. Accepts ISO 639-1 and ISO 639-2 codes.
*
* @param string $language
*
* @return CatalogInterface
*/
public function createCatalogByLanguage(string $language)
public function createCatalogByLanguage($language)
{
foreach ($this->loader->getCatalogs() as $catalog) {
if ($catalog::getIso639Alpha2() === $language || $catalog::getIso639Alpha3() === $language) {
Expand Down
15 changes: 14 additions & 1 deletion src/Loader/ArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

namespace AvaiBookSports\Component\RedsysMessages\Loader;

use AvaiBookSports\Component\RedsysMessages\CatalogInterface;

class ArrayLoader implements CatalogLoaderInterface
{
/**
* @var class-string<CatalogInterface>[]
*/
private $catalogs = [];

/**
* Initialize with a FQCN catalog list.
*
* @param class-string<CatalogInterface>[] $catalogs
*/
public function __construct(array $catalogs)
{
Expand All @@ -18,11 +25,17 @@ public function __construct(array $catalogs)

/**
* Add a catalog FQCN to the loader.
*
* @param class-string<CatalogInterface> $catalogClass
*
* @return self
*/
public function addCatalog(string $catalogClass)
public function addCatalog($catalogClass)
{
$this->catalogs[] = $catalogClass;
$this->catalogs = array_unique($this->catalogs);

return $this;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Loader/CatalogLoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace AvaiBookSports\Component\RedsysMessages\Loader;

use AvaiBookSports\Component\RedsysMessages\CatalogInterface;

interface CatalogLoaderInterface
{
/**
* Get a FQCN catalog list.
*
* @return array
* @return class-string<CatalogInterface>[]
*/
public function getCatalogs();
}
5 changes: 5 additions & 0 deletions src/Loader/ChainLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ public function __construct(array $loaders = [])
}
}

/**
* @return self
*/
public function addLoader(CatalogLoaderInterface $loader)
{
$this->loader[] = $loader;

return $this;
}

/**
Expand Down

0 comments on commit 007b0cd

Please sign in to comment.