TASK: Adding PHP 7.4 type hints everywhere
This commit is contained in:
parent
e8b75b33dd
commit
7c60f2f55e
5 changed files with 24 additions and 15 deletions
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Command;
|
||||
|
||||
use DigiComp\Sequence\Service\SequenceGenerator;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Domain\Model;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -20,20 +22,20 @@ class Insert
|
|||
* @Flow\Identity
|
||||
* @ORM\Id
|
||||
*/
|
||||
protected $number;
|
||||
protected int $number;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @Flow\Identity
|
||||
* @ORM\Id
|
||||
*/
|
||||
protected $type;
|
||||
protected string $type;
|
||||
|
||||
/**
|
||||
* @param int $number
|
||||
* @param string|object $type
|
||||
*/
|
||||
public function __construct($number, $type)
|
||||
public function __construct(int $number, $type)
|
||||
{
|
||||
$this->setNumber($number);
|
||||
$this->setType($type);
|
||||
|
@ -42,7 +44,7 @@ class Insert
|
|||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNumber()
|
||||
public function getNumber(): int
|
||||
{
|
||||
return $this->number;
|
||||
}
|
||||
|
@ -50,7 +52,7 @@ class Insert
|
|||
/**
|
||||
* @param int $number
|
||||
*/
|
||||
public function setNumber($number)
|
||||
public function setNumber(int $number): void
|
||||
{
|
||||
$this->number = $number;
|
||||
}
|
||||
|
@ -58,7 +60,7 @@ class Insert
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ class Insert
|
|||
/**
|
||||
* @param string|object $type
|
||||
*/
|
||||
public function setType($type)
|
||||
public function setType($type): void
|
||||
{
|
||||
if (is_object($type)) {
|
||||
$type = get_class($type);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Service;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Service;
|
||||
|
||||
use DigiComp\Sequence\Domain\Model\Insert;
|
||||
|
@ -36,7 +38,7 @@ class SequenceGenerator
|
|||
* @param string|object $type
|
||||
* @return int
|
||||
*/
|
||||
public function getNextNumberFor($type)
|
||||
public function getNextNumberFor($type): int
|
||||
{
|
||||
$type = $this->inferTypeFromSource($type);
|
||||
$count = $this->getLastNumberFor($type);
|
||||
|
@ -55,7 +57,7 @@ class SequenceGenerator
|
|||
* @param string|object $type
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateFreeNumber($count, $type)
|
||||
protected function validateFreeNumber(int $count, $type)
|
||||
{
|
||||
/* @var EntityManager $em */
|
||||
$em = $this->entityManager;
|
||||
|
@ -83,7 +85,7 @@ class SequenceGenerator
|
|||
* @param string|object $type
|
||||
* @return bool
|
||||
*/
|
||||
public function advanceTo($to, $type)
|
||||
public function advanceTo(int $to, $type): bool
|
||||
{
|
||||
$type = $this->inferTypeFromSource($type);
|
||||
|
||||
|
@ -94,12 +96,12 @@ class SequenceGenerator
|
|||
* @param string|object $type
|
||||
* @return int
|
||||
*/
|
||||
public function getLastNumberFor($type)
|
||||
public function getLastNumberFor($type): int
|
||||
{
|
||||
/* @var EntityManager $em */
|
||||
$em = $this->entityManager;
|
||||
|
||||
return $em->getConnection()->executeQuery(
|
||||
return (int) $em->getConnection()->executeQuery(
|
||||
'SELECT MAX(number) FROM ' . $em->getClassMetadata(Insert::class)->getTableName() . ' WHERE type = :type',
|
||||
['type' => $this->inferTypeFromSource($type)]
|
||||
)->fetchAll(\PDO::FETCH_COLUMN)[0];
|
||||
|
@ -110,7 +112,7 @@ class SequenceGenerator
|
|||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function inferTypeFromSource($stringOrObject)
|
||||
protected function inferTypeFromSource($stringOrObject): string
|
||||
{
|
||||
if (is_object($stringOrObject)) {
|
||||
$stringOrObject = TypeHandling::getTypeForValue($stringOrObject);
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
"license": "MIT",
|
||||
"homepage": "https://github.com/digicomp/DigiComp.Sequence",
|
||||
"require": {
|
||||
"neos/flow": "~4.1|~5.3|~6.3"
|
||||
"neos/flow": "~5.3 | ^6.3.5",
|
||||
"php": "^7.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
|
@ -33,7 +34,7 @@
|
|||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-version/1.x-dev": "1.1.x-dev",
|
||||
"dev-develop": "2.0.x-dev"
|
||||
"dev-develop": "3.0.x-dev"
|
||||
},
|
||||
"applied-flow-migrations": [
|
||||
"Inwebs.Basket-201409170938",
|
||||
|
|
Loading…
Reference in a new issue