Skip to content

Commit

Permalink
Fix deprecation notice in PHP 8.1 + add PHP Code Sniffer (#56)
Browse files Browse the repository at this point in the history
* Fix deprecation notice in PHP 8.1 + add PHP Code Sniffer

* Remove phpcompatibility
  • Loading branch information
dlakomski authored May 25, 2022
1 parent bd9d80b commit 060f052
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ jobs:

- name: "Psalm"
run: ./bin/psalm

- name: "CodeSniffer"
run: ./bin/phpcs
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"phpunit/phpunit": "^9.0",
"phpstan/extension-installer": "^1.0",
"vimeo/psalm": "^4.0",
"friends-of-phpspec/phpspec-code-coverage": "^6.0"
"friends-of-phpspec/phpspec-code-coverage": "^6.0",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="Gowork">
<description>The coding standard of Gowork.</description>

<file>src</file>

<rule ref="PSR1"/>
<rule ref="PSR2">
<exclude name="PSR2.ControlStructures.ControlStructureSpacing" />
<exclude name="PSR2.Namespaces.UseDeclaration" />
</rule>
<rule ref="PSR12">
<exclude name="PSR12.Files.OpenTag" />
<exclude name="PSR12.Files.FileHeader" />
</rule>

</ruleset>
4 changes: 2 additions & 2 deletions src/ArrayValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public function offsetExists($offset): bool;

/**
* @param int $offset
* @phpstan-return TValue
* @return ?TValue
*/
public function offsetGet($offset);
public function offsetGet($offset): mixed;

/**
* @param int $offset
Expand Down
2 changes: 1 addition & 1 deletion src/AssocArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function offsetExists($offset): bool
* @param TKey $offset
* @return ?TValue
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return $this->items->toAssocArray()[$offset];
}
Expand Down
4 changes: 2 additions & 2 deletions src/AssocValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public function reverse(): AssocValue;
public function offsetExists($offset): bool;

/**
* @phpstan-param TKey $offset
* @param TKey $offset
* @return ?TValue
*/
public function offsetGet($offset);
public function offsetGet($offset): mixed;

/**
* @phpstan-param TKey $offset
Expand Down
6 changes: 4 additions & 2 deletions src/InfiniteIterableValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function each(callable $callback): InfiniteIterableValue
}

/**
* @param (callable(TValue,TValue):int) | null $comparator
* @phpstan-param (callable(TValue,TValue):int) | null $comparator
* @phpstan-return InfiniteIterableValue<TKey, TValue>
*/
public function unique(?callable $comparator = null): InfiniteIterableValue
Expand Down Expand Up @@ -505,7 +505,9 @@ public function first()
public function last()
{
$value = null;
foreach ($this->stack->iterate() as $value) {}
foreach ($this->stack->iterate() as $value) {
// iterating until the end
}

return $value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PlainArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function shift(&$value = null): PlainArray
$items = $this->toArray();
$value = array_shift($items);

return new self(new JustArray($items));;
return new self(new JustArray($items));
}

/**
Expand Down Expand Up @@ -413,7 +413,7 @@ public function offsetExists($offset): bool
* @param int $offset
* @return ?TValue
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return $this->items->toArray()[$offset];
}
Expand Down
2 changes: 1 addition & 1 deletion src/PlainStringsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function offsetExists($offset): bool
/**
* @param int $offset
*/
public function offsetGet($offset): StringValue
public function offsetGet($offset): ?StringValue
{
return $this->strings->offsetGet($offset);
}
Expand Down
2 changes: 1 addition & 1 deletion src/StringsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function offsetExists($offset): bool;
/**
* @param int $offset
*/
public function offsetGet($offset): StringValue;
public function offsetGet($offset): ?StringValue;

/**
* @param int $offset
Expand Down

0 comments on commit 060f052

Please sign in to comment.