Skip to content

Commit 3d2b2cc

Browse files
authored
Merge pull request #4 from byjg/5.0
PHP 8.1 Implementation
2 parents 9de7b29 + b3f9864 commit 3d2b2cc

11 files changed

+60
-17
lines changed

.github/FUNDING.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: byjg

.github/workflows/phpunit.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ jobs:
1616
strategy:
1717
matrix:
1818
php-version:
19+
- "8.3"
1920
- "8.2"
2021
- "8.1"
21-
- "8.0"
22-
- "7.4"
2322

2423
steps:
2524
- uses: actions/checkout@v4
2625
- run: composer install
2726
- run: ./vendor/bin/phpunit
27+
- run: ./vendor/bin/psalm
2828

2929
Documentation:
3030
if: github.ref == 'refs/heads/master'

.run/PHPUnit.run.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="PHPUnit" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
3+
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" scope="XML" use_alternative_configuration_file="true" />
4+
<method v="2" />
5+
</configuration>
6+
</component>

.run/PSalm.run.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="PSalm" type="PhpLocalRunConfigurationType" factoryName="PHP Console" path="$PROJECT_DIR$/vendor/bin/psalm">
3+
<method v="2" />
4+
</configuration>
5+
</component>

composer.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
"ByJG\\DesignPattern\\": "src/"
77
}
88
},
9+
"autoload-dev": {
10+
"psr-4": {
11+
"Tests\\": "tests/"
12+
}
13+
},
914
"require": {
10-
"php": ">=7.4"
15+
"php": ">=8.1 <8.4"
1116
},
1217
"require-dev": {
13-
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
18+
"phpunit/phpunit": "^9.6",
19+
"vimeo/psalm": "^5.9"
1420
},
1521
"license": "MIT"
1622
}

psalm.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
findUnusedBaselineEntry="true"
6+
findUnusedCode="false"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<directory name="tests" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
</psalm>

src/Singleton.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __wakeup()
3636
/**
3737
* @return static
3838
*/
39-
public static function getInstance()
39+
public static function getInstance(): static
4040
{
4141
static $instances;
4242

src/SingletonException.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace ByJG\DesignPattern;
44

5-
class SingletonException extends \Exception
5+
use Exception;
6+
7+
class SingletonException extends Exception
68
{
79

810
}

tests/Sample1.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3-
require_once __DIR__ . "/../vendor/autoload.php";
3+
namespace Tests;
4+
5+
use ByJG\DesignPattern\Singleton;
46

57
class Sample1
68
{
7-
use \ByJG\DesignPattern\Singleton;
9+
use Singleton;
810

9-
public $property;
11+
public int $property;
1012

1113
private function __construct()
1214
{

tests/Sample2.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3-
require_once __DIR__ . "/../vendor/autoload.php";
3+
namespace Tests;
4+
5+
use ByJG\DesignPattern\Singleton;
46

57
class Sample2
68
{
7-
use \ByJG\DesignPattern\Singleton;
9+
use Singleton;
810

9-
public $property2;
11+
public int $property2;
1012
}

tests/SingletonTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22

3-
use ByJG\DesignPattern\SingletonException;
3+
namespace Tests;
44

5-
require_once __DIR__ . "/../vendor/autoload.php";
6-
require_once "Sample1.php";
7-
require_once "Sample2.php";
5+
use ByJG\DesignPattern\SingletonException;
6+
use PHPUnit\Framework\TestCase;
87

9-
class SingletonTest extends \PHPUnit\Framework\TestCase
8+
class SingletonTest extends TestCase
109
{
1110
public function testSingleton()
1211
{

0 commit comments

Comments
 (0)