mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-11 17:34:09 +02:00
update deps & install rector
This commit is contained in:
@@ -2,17 +2,14 @@
|
||||
|
||||
namespace DesignPatterns\Creational\StaticFactory;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Note1: Remember, static means global state which is evil because it can't be mocked for tests
|
||||
* Note2: Cannot be subclassed or mock-upped or have multiple different instances.
|
||||
*/
|
||||
final class StaticFactory
|
||||
{
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return Formatter
|
||||
*/
|
||||
public static function factory(string $type): Formatter
|
||||
{
|
||||
if ($type == 'number') {
|
||||
@@ -21,6 +18,6 @@ final class StaticFactory
|
||||
return new FormatString();
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Unknown format given');
|
||||
throw new InvalidArgumentException('Unknown format given');
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace DesignPatterns\Creational\StaticFactory\Tests;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use DesignPatterns\Creational\StaticFactory\FormatNumber;
|
||||
use DesignPatterns\Creational\StaticFactory\FormatString;
|
||||
use DesignPatterns\Creational\StaticFactory\StaticFactory;
|
||||
@@ -21,7 +22,7 @@ class StaticFactoryTest extends TestCase
|
||||
|
||||
public function testException()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
StaticFactory::factory('object');
|
||||
}
|
||||
|
Reference in New Issue
Block a user