Skip to content

Commit 4012f26

Browse files
authored
refactor: Add native parameter types & return type when possible (#353)
Native parameter types are added for all arguments. Return types are added only for private methods as adding a returning type on an method that can be overriden is a BC break.
1 parent b710691 commit 4012f26

29 files changed

+69
-117
lines changed

src/Cache/CacheInterface.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface CacheInterface
2727
*
2828
* @return bool
2929
*/
30-
public function isFresh($path, $timestamp);
30+
public function isFresh(string $path, int $timestamp);
3131

3232
/**
3333
* Reads feature cache from path.
@@ -36,15 +36,14 @@ public function isFresh($path, $timestamp);
3636
*
3737
* @return FeatureNode
3838
*/
39-
public function read($path);
39+
public function read(string $path);
4040

4141
/**
4242
* Caches feature node.
4343
*
4444
* @param string $path Feature path
45-
* @param FeatureNode $feature Feature instance
4645
*
4746
* @return void
4847
*/
49-
public function write($path, FeatureNode $feature);
48+
public function write(string $path, FeatureNode $feature);
5049
}

src/Cache/FileCache.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(string $path)
6363
*
6464
* @return bool
6565
*/
66-
public function isFresh($path, $timestamp)
66+
public function isFresh(string $path, int $timestamp)
6767
{
6868
$cachePath = $this->getCachePathFor($path);
6969

@@ -83,7 +83,7 @@ public function isFresh($path, $timestamp)
8383
*
8484
* @throws CacheException
8585
*/
86-
public function read($path)
86+
public function read(string $path)
8787
{
8888
$cachePath = $this->getCachePathFor($path);
8989
$feature = unserialize(file_get_contents($cachePath));
@@ -99,11 +99,10 @@ public function read($path)
9999
* Caches feature node.
100100
*
101101
* @param string $path Feature path
102-
* @param FeatureNode $feature Feature instance
103102
*
104103
* @return void
105104
*/
106-
public function write($path, FeatureNode $feature)
105+
public function write(string $path, FeatureNode $feature)
107106
{
108107
file_put_contents($this->getCachePathFor($path), serialize($feature));
109108
}
@@ -115,7 +114,7 @@ public function write($path, FeatureNode $feature)
115114
*
116115
* @return string
117116
*/
118-
protected function getCachePathFor($path)
117+
protected function getCachePathFor(string $path)
119118
{
120119
return $this->path . '/' . md5($path) . '.feature.cache';
121120
}

src/Cache/MemoryCache.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MemoryCache implements CacheInterface
3737
*
3838
* @return bool
3939
*/
40-
public function isFresh($path, $timestamp)
40+
public function isFresh(string $path, int $timestamp)
4141
{
4242
if (!isset($this->features[$path])) {
4343
return false;
@@ -53,7 +53,7 @@ public function isFresh($path, $timestamp)
5353
*
5454
* @return FeatureNode
5555
*/
56-
public function read($path)
56+
public function read(string $path)
5757
{
5858
return $this->features[$path];
5959
}
@@ -62,11 +62,10 @@ public function read($path)
6262
* Caches feature node.
6363
*
6464
* @param string $path Feature path
65-
* @param FeatureNode $feature Feature instance
6665
*
6766
* @return void
6867
*/
69-
public function write($path, FeatureNode $feature)
68+
public function write(string $path, FeatureNode $feature)
7069
{
7170
$this->features[$path] = $feature;
7271
$this->timestamps[$path] = time();

src/Filter/LineFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LineFilter implements FilterInterface
3232
*
3333
* @param int|numeric-string $filterLine Line of the scenario to filter on
3434
*/
35-
public function __construct($filterLine)
35+
public function __construct(int|string $filterLine)
3636
{
3737
$this->filterLine = (int) $filterLine;
3838
}

src/Filter/LineRangeFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class LineRangeFilter implements FilterInterface
3737
* @param int|numeric-string $filterMinLine Minimum line of a scenario to filter on
3838
* @param int|numeric-string|'*' $filterMaxLine Maximum line of a scenario to filter on
3939
*/
40-
public function __construct($filterMinLine, $filterMaxLine)
40+
public function __construct(int|string $filterMinLine, int|string $filterMaxLine)
4141
{
4242
$this->filterMinLine = (int) $filterMinLine;
4343
$this->filterMaxLine = $filterMaxLine === '*' ? PHP_INT_MAX : (int) $filterMaxLine;

src/Filter/NameFilter.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ class NameFilter extends SimpleFilter
2525
*/
2626
protected $filterString;
2727

28-
/**
29-
* Initializes filter.
30-
*
31-
* @param string $filterString Name filter string
32-
*/
33-
public function __construct($filterString)
28+
public function __construct(string $filterString)
3429
{
3530
$this->filterString = trim($filterString);
3631
}

src/Filter/RoleFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RoleFilter extends SimpleFilter
3030
*
3131
* @param string $role Approved role wildcard
3232
*/
33-
public function __construct($role)
33+
public function __construct(string $role)
3434
{
3535
$this->pattern = sprintf(
3636
'/as an? %s[$\n]/i',

src/Filter/TagFilter.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ class TagFilter extends ComplexFilter
2626
*/
2727
protected $filterString;
2828

29-
/**
30-
* Initializes filter.
31-
*
32-
* @param string $filterString Name filter string
33-
*/
34-
public function __construct($filterString)
29+
public function __construct(string $filterString)
3530
{
3631
$this->filterString = trim($filterString);
3732

@@ -116,7 +111,7 @@ public function isScenarioMatch(FeatureNode $feature, ScenarioInterface $scenari
116111
*
117112
* @return bool
118113
*/
119-
protected function isTagsMatchCondition($tags)
114+
protected function isTagsMatchCondition(array $tags)
120115
{
121116
if ($this->filterString === '') {
122117
return true;

src/Gherkin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function setFilters(array $filters)
8484
*
8585
* @return void
8686
*/
87-
public function setBasePath($path)
87+
public function setBasePath(string $path)
8888
{
8989
foreach ($this->loaders as $loader) {
9090
if ($loader instanceof FileLoaderInterface) {
@@ -143,7 +143,7 @@ public function load($resource, array $filters = [])
143143
*
144144
* @return LoaderInterface|null
145145
*/
146-
public function resolveLoader($resource)
146+
public function resolveLoader(mixed $resource)
147147
{
148148
foreach ($this->loaders as $loader) {
149149
if ($loader->supports($resource)) {

src/Keywords/ArrayKeywords.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ public function __construct(
6565
/**
6666
* Sets keywords holder language.
6767
*
68-
* @param string $language Language name
69-
*
7068
* @return void
7169
*/
72-
public function setLanguage($language)
70+
public function setLanguage(string $language)
7371
{
7472
if (!isset($this->keywords[$language])) {
7573
$this->language = 'en';

0 commit comments

Comments
 (0)