add psalm and travis check

This commit is contained in:
Dominik Liebler
2019-08-31 14:31:01 +02:00
parent 88bd6ab7f1
commit 5fb2980b45
17 changed files with 1215 additions and 45 deletions

View File

@@ -2,10 +2,12 @@
namespace DesignPatterns\More\EAV;
use SplObjectStorage;
class Entity
{
/**
* @var \SplObjectStorage
* @var SplObjectStorage<Value,Value>
*/
private $values;
@@ -20,7 +22,7 @@ class Entity
*/
public function __construct(string $name, $values)
{
$this->values = new \SplObjectStorage();
$this->values = new SplObjectStorage();
$this->name = $name;
foreach ($values as $value) {

View File

@@ -24,6 +24,6 @@ class Value
public function __toString(): string
{
return sprintf('%s: %s', $this->attribute, $this->name);
return sprintf('%s: %s', (string) $this->attribute, $this->name);
}
}

View File

@@ -5,18 +5,17 @@ namespace DesignPatterns\More\ServiceLocator;
class ServiceLocator
{
/**
* @var array|Service[]
* @var string[][]
*/
private $services = [];
/**
* @var array|Service[]
* @var Service[]
*/
private $instantiated = [];
public function addInstance(string $class, Service $service)
{
$this->services[$class] = $service;
$this->instantiated[$class] = $service;
}
@@ -55,6 +54,10 @@ class ServiceLocator
throw new \OutOfRangeException('Too many arguments given');
}
if (!$object instanceof Service) {
throw new \InvalidArgumentException('Could not register service: is no instance of Service');
}
$this->instantiated[$class] = $object;
return $object;