Skip to content

Commit

Permalink
Compatibility with PHP 8.1 & 8.2 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
javierabion authored May 11, 2023
1 parent 6046370 commit c784361
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
strategy:
matrix:
php-versions:
- 5.6
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
name: PHP ${{ matrix.php-versions }}
steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ We accept contributions via Pull Requests on [Github](https://github.com/Speiche
## Running Tests

``` bash
$ phpunit
$ vendor/bin/simple-phpunit
```


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Please see [USAGE](docs/usage.md) for details.
## Testing

``` bash
$ phpunit
$ vendor/bin/simple-phpunit
```

## Contributing
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
}
],
"require": {
"php": ">=5.4"
"php": ">=7.2"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0",
"symfony/phpunit-bridge": "^6.0",
"scrutinizer/ocular": "~1.1"
},
"autoload": {
Expand Down
46 changes: 19 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Wingu OctopusCore Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Wingu OctopusCore Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
4 changes: 2 additions & 2 deletions src/Annotation/Tags/BaseTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function __construct(AnnotationDefinition $definition)
/**
* Initialize the annotation tag.
*/
protected function initTag()
protected function initTag(): void
{
$this->tagName = $this->definition->getTag();

$description = trim($this->definition->getDescription());
$description = trim(($this->definition->getDescription())??'');
if ($description !== '') {
$this->description = trim($this->definition->getDescription());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Annotation/Tags/ParamTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function __construct(AnnotationDefinition $definition)
/**
* Initialize the annotation tag.
*/
protected function initTag()
protected function initTag(): void
{
parent::initTag();

$value = preg_split('/[\s]+/', $this->description, 3);
$value = preg_split('/[\s]+/', $this->description??'', 3);

if (isset($value[0]) === true && trim($value[0]) !== '') {
$this->paramType = trim($value[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/Annotation/Tags/ReturnTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function __construct(AnnotationDefinition $definition)
/**
* Initialize the annotation tag.
*/
protected function initTag()
protected function initTag(): void
{
parent::initTag();

$value = preg_split('/[\s]+/', $this->description, 2);
$value = preg_split('/[\s]+/', $this->description??'', 2);
if (isset($value[0]) === true && trim($value[0]) !== '') {
$this->returnType = $value[0];
}
Expand Down
19 changes: 10 additions & 9 deletions src/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getBody()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass[]
*/
public function getInterfaces()
public function getInterfaces(): array
{
$return = array();

Expand Down Expand Up @@ -78,7 +78,7 @@ public function getOwnInterfaces()
* @param string $name The method name.
* @return \Wingu\OctopusCore\Reflection\ReflectionMethod
*/
public function getMethod($name)
public function getMethod($name): ReflectionMethod
{
return new ReflectionMethod($this->getName(), $name);
}
Expand All @@ -89,7 +89,7 @@ public function getMethod($name)
* @param integer $filter Filter for method types. This is an OR filter only.
* @return \Wingu\OctopusCore\Reflection\ReflectionMethod[]
*/
public function getMethods($filter = -1)
public function getMethods($filter = -1): array
{
$return = parent::getMethods($filter);
foreach ($return as $key => $val) {
Expand Down Expand Up @@ -135,7 +135,7 @@ public function getOwnMethods($filter = -1)
*
* @return \Wingu\OctopusCore\Reflection\ReflectionMethod
*/
public function getConstructor()
public function getConstructor(): ?ReflectionMethod
{
if ($this->hasMethod('__construct') === true) {
return $this->getMethod('__construct');
Expand Down Expand Up @@ -164,6 +164,7 @@ public function hasOwnMethod($name)
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass
*/
#[\ReturnTypeWillChange]
public function getParentClass()
{
$parent = parent::getParentClass();
Expand All @@ -177,7 +178,7 @@ public function getParentClass()
* @param string $name Name of the property.
* @return \Wingu\OctopusCore\Reflection\ReflectionProperty
*/
public function getProperty($name)
public function getProperty($name): ReflectionProperty
{
return new ReflectionProperty($this->getName(), $name);
}
Expand All @@ -188,7 +189,7 @@ public function getProperty($name)
* @param integer $filter Filter for the properties.
* @return \Wingu\OctopusCore\Reflection\ReflectionProperty[]
*/
public function getProperties($filter = -1)
public function getProperties($filter = -1): array
{
$properties = parent::getProperties($filter);
foreach ($properties as $key => $val) {
Expand Down Expand Up @@ -231,7 +232,7 @@ public function getOwnProperties($filter = -1)
*
* @return \Wingu\OctopusCore\Reflection\ReflectionConstant[] the array of constants
*/
public function getConstants($filter = null)
public function getConstants($filter = null): array
{
$constants = parent::getConstants();
$returnConstants = array();
Expand Down Expand Up @@ -261,7 +262,7 @@ public function getOwnConstants()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass[]
*/
public function getTraits()
public function getTraits(): array
{
$return = parent::getTraits();
if ($return !== null) {
Expand Down Expand Up @@ -293,7 +294,7 @@ public function getUses()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionExtension
*/
public function getExtension()
public function getExtension(): ?ReflectionExtension
{
$extensionName = $this->getExtensionName();
if ($extensionName !== false) {
Expand Down
4 changes: 2 additions & 2 deletions src/ReflectionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getBody()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionExtension
*/
public function getExtension()
public function getExtension(): ?ReflectionExtension
{
$extensionName = $this->getExtensionName();
if ($extensionName !== false) {
Expand All @@ -57,7 +57,7 @@ public function getExtension()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionParameter[]
*/
public function getParameters()
public function getParameters(): array
{
$res = parent::getParameters();

Expand Down
8 changes: 4 additions & 4 deletions src/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ReflectionMethod extends \ReflectionMethod
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass
*/
public function getDeclaringClass()
public function getDeclaringClass(): ReflectionClass
{
return new ReflectionClass(parent::getDeclaringClass()->getName());
}
Expand All @@ -27,7 +27,7 @@ public function getDeclaringClass()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionMethod
*/
public function getPrototype()
public function getPrototype(): ReflectionMethod
{
$prototype = parent::getPrototype();

Expand Down Expand Up @@ -68,7 +68,7 @@ public function getBody()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionParameter[]
*/
public function getParameters()
public function getParameters(): array
{
$function = array($this->getDeclaringClass()->getName(), $this->getName());
$res = parent::getParameters();
Expand All @@ -85,7 +85,7 @@ public function getParameters()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionExtension
*/
public function getExtension()
public function getExtension(): ?ReflectionExtension
{
$extensionName = $this->getExtensionName();
if ($extensionName !== false) {
Expand Down
6 changes: 3 additions & 3 deletions src/ReflectionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($function, $parameter)
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass
*/
public function getClass()
public function getClass(): ?ReflectionClass
{
$class = null;
if (PHP_VERSION_ID < 80000) {
Expand All @@ -55,7 +55,7 @@ public function getClass()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass
*/
public function getDeclaringClass()
public function getDeclaringClass(): ?ReflectionClass
{
$class = parent::getDeclaringClass();
if ($class !== null) {
Expand All @@ -70,7 +70,7 @@ public function getDeclaringClass()
*
* @return \Wingu\OctopusCore\Reflection\ReflectionMethod|\Wingu\OctopusCore\Reflection\ReflectionFunction
*/
public function getDeclaringFunction()
public function getDeclaringFunction(): \ReflectionFunctionAbstract
{
if (is_array($this->function) === true) {
return new ReflectionMethod($this->function[0], $this->function[1]);
Expand Down
3 changes: 2 additions & 1 deletion src/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ReflectionProperty extends \ReflectionProperty
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass
*/
public function getDeclaringClass()
public function getDeclaringClass(): ReflectionClass
{
return new ReflectionClass(parent::getDeclaringClass()->getName());
}
Expand All @@ -25,6 +25,7 @@ public function getDeclaringClass()
*
* @return mixed
*/
#[\ReturnTypeWillChange]
public function getDefaultValue()
{
return $this->getDeclaringClass()->getDefaultProperties()[$this->name];
Expand Down
8 changes: 2 additions & 6 deletions tests/Unit/ReflectionConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public function testGetDocCommentWithValidCommentReturnTheDocComment()
'CONSTANT2'
);
$actual = $reflectionConstant->getDocComment();
$expected = '/**
* This is *a comment* {};
*/';
$expected = "/**\n * This is *a comment* {};\n */";
$this->assertEquals($expected, $actual);
}

Expand All @@ -68,9 +66,7 @@ public function testGetDocCommentWithValidCommentInheritedReturnTheDocComment()
'CONSTANT3'
);
$actual = $reflectionConstant->getDocComment();
$expected = '/**
* This is *another comment*
*/';
$expected = "/**\n * This is *another comment*\n */";
$this->assertEquals($expected, $actual);
}

Expand Down
5 changes: 1 addition & 4 deletions tests/Unit/ReflectionMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ public function testGetBodyWithBodyReturnString()
$reflection = new ReflectionMethod('\Wingu\OctopusCore\Reflection\Tests\Unit\Fixtures\ImplementorClass3',
'methodWithNormalBody');
$actual = $reflection->getBody();
$expected = " echo 'test';
echo 'test';
echo 'test';
return 1;";
$expected = " echo 'test';\n echo 'test';\n echo 'test';\n return 1;";
$this->assertEquals($expected, $actual);
}

Expand Down

0 comments on commit c784361

Please sign in to comment.