TASK: Adding PHP 7.4 type hints everywhere

This commit is contained in:
Ferdinand Kuhl 2021-04-20 01:18:17 +02:00
parent e8b75b33dd
commit 7c60f2f55e
5 changed files with 24 additions and 15 deletions

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace DigiComp\Sequence\Command; namespace DigiComp\Sequence\Command;
use DigiComp\Sequence\Service\SequenceGenerator; use DigiComp\Sequence\Service\SequenceGenerator;

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace DigiComp\Sequence\Domain\Model; namespace DigiComp\Sequence\Domain\Model;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -20,20 +22,20 @@ class Insert
* @Flow\Identity * @Flow\Identity
* @ORM\Id * @ORM\Id
*/ */
protected $number; protected int $number;
/** /**
* @var string * @var string
* @Flow\Identity * @Flow\Identity
* @ORM\Id * @ORM\Id
*/ */
protected $type; protected string $type;
/** /**
* @param int $number * @param int $number
* @param string|object $type * @param string|object $type
*/ */
public function __construct($number, $type) public function __construct(int $number, $type)
{ {
$this->setNumber($number); $this->setNumber($number);
$this->setType($type); $this->setType($type);
@ -42,7 +44,7 @@ class Insert
/** /**
* @return int * @return int
*/ */
public function getNumber() public function getNumber(): int
{ {
return $this->number; return $this->number;
} }
@ -50,7 +52,7 @@ class Insert
/** /**
* @param int $number * @param int $number
*/ */
public function setNumber($number) public function setNumber(int $number): void
{ {
$this->number = $number; $this->number = $number;
} }
@ -58,7 +60,7 @@ class Insert
/** /**
* @return string * @return string
*/ */
public function getType() public function getType(): string
{ {
return $this->type; return $this->type;
} }
@ -66,7 +68,7 @@ class Insert
/** /**
* @param string|object $type * @param string|object $type
*/ */
public function setType($type) public function setType($type): void
{ {
if (is_object($type)) { if (is_object($type)) {
$type = get_class($type); $type = get_class($type);

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace DigiComp\Sequence\Service; namespace DigiComp\Sequence\Service;
/** /**

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace DigiComp\Sequence\Service; namespace DigiComp\Sequence\Service;
use DigiComp\Sequence\Domain\Model\Insert; use DigiComp\Sequence\Domain\Model\Insert;
@ -36,7 +38,7 @@ class SequenceGenerator
* @param string|object $type * @param string|object $type
* @return int * @return int
*/ */
public function getNextNumberFor($type) public function getNextNumberFor($type): int
{ {
$type = $this->inferTypeFromSource($type); $type = $this->inferTypeFromSource($type);
$count = $this->getLastNumberFor($type); $count = $this->getLastNumberFor($type);
@ -55,7 +57,7 @@ class SequenceGenerator
* @param string|object $type * @param string|object $type
* @return bool * @return bool
*/ */
protected function validateFreeNumber($count, $type) protected function validateFreeNumber(int $count, $type)
{ {
/* @var EntityManager $em */ /* @var EntityManager $em */
$em = $this->entityManager; $em = $this->entityManager;
@ -83,7 +85,7 @@ class SequenceGenerator
* @param string|object $type * @param string|object $type
* @return bool * @return bool
*/ */
public function advanceTo($to, $type) public function advanceTo(int $to, $type): bool
{ {
$type = $this->inferTypeFromSource($type); $type = $this->inferTypeFromSource($type);
@ -94,12 +96,12 @@ class SequenceGenerator
* @param string|object $type * @param string|object $type
* @return int * @return int
*/ */
public function getLastNumberFor($type) public function getLastNumberFor($type): int
{ {
/* @var EntityManager $em */ /* @var EntityManager $em */
$em = $this->entityManager; $em = $this->entityManager;
return $em->getConnection()->executeQuery( return (int) $em->getConnection()->executeQuery(
'SELECT MAX(number) FROM ' . $em->getClassMetadata(Insert::class)->getTableName() . ' WHERE type = :type', 'SELECT MAX(number) FROM ' . $em->getClassMetadata(Insert::class)->getTableName() . ' WHERE type = :type',
['type' => $this->inferTypeFromSource($type)] ['type' => $this->inferTypeFromSource($type)]
)->fetchAll(\PDO::FETCH_COLUMN)[0]; )->fetchAll(\PDO::FETCH_COLUMN)[0];
@ -110,7 +112,7 @@ class SequenceGenerator
* @return string * @return string
* @throws Exception * @throws Exception
*/ */
protected function inferTypeFromSource($stringOrObject) protected function inferTypeFromSource($stringOrObject): string
{ {
if (is_object($stringOrObject)) { if (is_object($stringOrObject)) {
$stringOrObject = TypeHandling::getTypeForValue($stringOrObject); $stringOrObject = TypeHandling::getTypeForValue($stringOrObject);

View file

@ -19,7 +19,8 @@
"license": "MIT", "license": "MIT",
"homepage": "https://github.com/digicomp/DigiComp.Sequence", "homepage": "https://github.com/digicomp/DigiComp.Sequence",
"require": { "require": {
"neos/flow": "~4.1|~5.3|~6.3" "neos/flow": "~5.3 | ^6.3.5",
"php": "^7.4"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "3.7.*", "phpunit/phpunit": "3.7.*",
@ -33,7 +34,7 @@
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-version/1.x-dev": "1.1.x-dev", "dev-version/1.x-dev": "1.1.x-dev",
"dev-develop": "2.0.x-dev" "dev-develop": "3.0.x-dev"
}, },
"applied-flow-migrations": [ "applied-flow-migrations": [
"Inwebs.Basket-201409170938", "Inwebs.Basket-201409170938",