Skip to content

Commit 5fb2980

Browse files
author
Dominik Liebler
committed
add psalm and travis check
1 parent 88bd6ab commit 5fb2980

File tree

17 files changed

+1850
-680
lines changed

17 files changed

+1850
-680
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ install:
2424
script:
2525
- vendor/bin/phpunit
2626
- vendor/bin/phpcs .
27+
- vendor/bin/psalm --show-info=false

Behavioral/ChainOfResponsibilities/Tests/ChainTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
use DesignPatterns\Behavioral\ChainOfResponsibilities\Handler;
66
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\HttpInMemoryCacheHandler;
77
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowDatabaseHandler;
8+
use PHPUnit\Framework\MockObject\MockObject;
89
use PHPUnit\Framework\TestCase;
10+
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\UriInterface;
912

1013
class ChainTest extends TestCase
1114
{
@@ -24,11 +27,11 @@ protected function setUp(): void
2427

2528
public function testCanRequestKeyInFastStorage()
2629
{
27-
$uri = $this->createMock('Psr\Http\Message\UriInterface');
30+
$uri = $this->createMock(UriInterface::class);
2831
$uri->method('getPath')->willReturn('/foo/bar');
2932
$uri->method('getQuery')->willReturn('index=1');
3033

31-
$request = $this->createMock('Psr\Http\Message\RequestInterface');
34+
$request = $this->createMock(RequestInterface::class);
3235
$request->method('getMethod')
3336
->willReturn('GET');
3437
$request->method('getUri')->willReturn($uri);
@@ -38,11 +41,11 @@ public function testCanRequestKeyInFastStorage()
3841

3942
public function testCanRequestKeyInSlowStorage()
4043
{
41-
$uri = $this->createMock('Psr\Http\Message\UriInterface');
44+
$uri = $this->createMock(UriInterface::class);
4245
$uri->method('getPath')->willReturn('/foo/baz');
4346
$uri->method('getQuery')->willReturn('');
4447

45-
$request = $this->createMock('Psr\Http\Message\RequestInterface');
48+
$request = $this->createMock(RequestInterface::class);
4649
$request->method('getMethod')
4750
->willReturn('GET');
4851
$request->method('getUri')->willReturn($uri);

Behavioral/Observer/UserObserver.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22

33
namespace DesignPatterns\Behavioral\Observer;
44

5+
use SplSubject;
6+
57
class UserObserver implements \SplObserver
68
{
79
/**
8-
* @var User[]
10+
* @var SplSubject[]
911
*/
1012
private $changedUsers = [];
1113

1214
/**
1315
* It is called by the Subject, usually by SplSubject::notify()
1416
*
15-
* @param \SplSubject $subject
17+
* @param SplSubject $subject
1618
*/
17-
public function update(\SplSubject $subject)
19+
public function update(SplSubject $subject)
1820
{
1921
$this->changedUsers[] = clone $subject;
2022
}
2123

2224
/**
23-
* @return User[]
25+
* @return SplSubject[]
2426
*/
2527
public function getChangedUsers(): array
2628
{

Behavioral/Specification/AndSpecification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AndSpecification implements Specification
1010
private $specifications;
1111

1212
/**
13-
* @param Specification[] ...$specifications
13+
* @param Specification[] $specifications
1414
*/
1515
public function __construct(Specification ...$specifications)
1616
{

Behavioral/Specification/OrSpecification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class OrSpecification implements Specification
1010
private $specifications;
1111

1212
/**
13-
* @param Specification[] ...$specifications
13+
* @param Specification[] $specifications
1414
*/
1515
public function __construct(Specification ...$specifications)
1616
{
1717
$this->specifications = $specifications;
1818
}
1919

20-
/**
20+
/*
2121
* if at least one specification is true, return true, else return false
2222
*/
2323
public function isSatisfiedBy(Item $item): bool

Creational/AbstractFactory/ShippableProduct.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
class ShippableProduct implements Product
66
{
77
/**
8-
* @var float
8+
* @var int
99
*/
1010
private $productPrice;
1111

1212
/**
13-
* @var float
13+
* @var int
1414
*/
1515
private $shippingCosts;
1616

Creational/StaticFactory/FormatNumber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class FormatNumber implements Formatter
66
{
77
public function format(string $input): string
88
{
9-
return number_format($input);
9+
return number_format((int) $input);
1010
}
1111
}

Creational/StaticFactory/Tests/StaticFactoryTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22

33
namespace DesignPatterns\Creational\StaticFactory\Tests;
44

5+
use DesignPatterns\Creational\StaticFactory\FormatNumber;
6+
use DesignPatterns\Creational\StaticFactory\FormatString;
57
use DesignPatterns\Creational\StaticFactory\StaticFactory;
68
use PHPUnit\Framework\TestCase;
79

810
class StaticFactoryTest extends TestCase
911
{
1012
public function testCanCreateNumberFormatter()
1113
{
12-
$this->assertInstanceOf(
13-
'DesignPatterns\Creational\StaticFactory\FormatNumber',
14-
StaticFactory::factory('number')
15-
);
14+
$this->assertInstanceOf(FormatNumber::class, StaticFactory::factory('number'));
1615
}
1716

1817
public function testCanCreateStringFormatter()
1918
{
20-
$this->assertInstanceOf(
21-
'DesignPatterns\Creational\StaticFactory\FormatString',
22-
StaticFactory::factory('string')
23-
);
19+
$this->assertInstanceOf(FormatString::class, StaticFactory::factory('string'));
2420
}
2521

2622
public function testException()

More/EAV/Entity.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace DesignPatterns\More\EAV;
44

5+
use SplObjectStorage;
6+
57
class Entity
68
{
79
/**
8-
* @var \SplObjectStorage
10+
* @var SplObjectStorage<Value,Value>
911
*/
1012
private $values;
1113

@@ -20,7 +22,7 @@ class Entity
2022
*/
2123
public function __construct(string $name, $values)
2224
{
23-
$this->values = new \SplObjectStorage();
25+
$this->values = new SplObjectStorage();
2426
$this->name = $name;
2527

2628
foreach ($values as $value) {

More/EAV/Value.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public function __construct(Attribute $attribute, string $name)
2424

2525
public function __toString(): string
2626
{
27-
return sprintf('%s: %s', $this->attribute, $this->name);
27+
return sprintf('%s: %s', (string) $this->attribute, $this->name);
2828
}
2929
}

0 commit comments

Comments
 (0)