From ee62e5e35aa61a4c141457ee53018182f3ad9dd9 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Tue, 4 Oct 2016 17:44:53 +0100 Subject: [PATCH] Remove instantiation restrictions --- src/CliMenu.php | 11 ----------- .../InvalidInstantiationException.php | 14 -------------- src/MenuStyle.php | 12 ------------ .../InvalidInstantiationExceptionTest.php | 19 ------------------- test/MenuStyleTest.php | 10 ---------- 5 files changed, 66 deletions(-) delete mode 100644 src/Exception/InvalidInstantiationException.php delete mode 100644 test/Exception/InvalidInstantiationExceptionTest.php diff --git a/src/CliMenu.php b/src/CliMenu.php index 49f561ec..c9314a30 100644 --- a/src/CliMenu.php +++ b/src/CliMenu.php @@ -49,11 +49,6 @@ class CliMenu */ protected $open = false; - /** - * @var string - */ - private $allowedConsumer = 'PhpSchool\CliMenu\CliMenuBuilder'; - /** * @var CliMenu|null */ @@ -73,12 +68,6 @@ public function __construct( TerminalInterface $terminal = null, MenuStyle $style = null ) { - $builder = debug_backtrace(); - if (count($builder) < 2 || !isset($builder[1]['class']) || $builder[1]['class'] !== $this->allowedConsumer) { - throw new InvalidInstantiationException( - sprintf('The CliMenu must be instantiated by "%s"', $this->allowedConsumer) - ); - } $this->title = $title; $this->items = $items; diff --git a/src/Exception/InvalidInstantiationException.php b/src/Exception/InvalidInstantiationException.php deleted file mode 100644 index c9ea1138..00000000 --- a/src/Exception/InvalidInstantiationException.php +++ /dev/null @@ -1,14 +0,0 @@ - - */ -class InvalidInstantiationException extends \Exception -{ - -} diff --git a/src/MenuStyle.php b/src/MenuStyle.php index fa25e1b9..6a1b1d43 100644 --- a/src/MenuStyle.php +++ b/src/MenuStyle.php @@ -76,11 +76,6 @@ class MenuStyle */ private $titleSeparator; - /** - * @var string - */ - private $allowedConsumer = 'PhpSchool\CliMenu\CliMenuBuilder'; - /** * @var array */ @@ -152,13 +147,6 @@ public function __construct( $titleSeparator = '=', TerminalInterface $terminal = null ) { - $builder = debug_backtrace(); - if (count($builder) < 2 || !isset($builder[1]['class']) || $builder[1]['class'] !== $this->allowedConsumer) { - throw new InvalidInstantiationException( - sprintf('The MenuStyle must be instantiated by "%s"', $this->allowedConsumer) - ); - } - $this->terminal = $terminal ?: TerminalFactory::fromSystem(); $this->bg = $bg; $this->fg = $fg; diff --git a/test/Exception/InvalidInstantiationExceptionTest.php b/test/Exception/InvalidInstantiationExceptionTest.php deleted file mode 100644 index 0aebbd6d..00000000 --- a/test/Exception/InvalidInstantiationExceptionTest.php +++ /dev/null @@ -1,19 +0,0 @@ - - */ -class InvalidInstantiationExceptionTest extends PHPUnit_Framework_TestCase -{ - public function testException() - { - $e = new InvalidInstantiationException('error'); - $this->assertEquals('error', $e->getMessage()); - } -} diff --git a/test/MenuStyleTest.php b/test/MenuStyleTest.php index 3f6feb1c..d27f3f1f 100644 --- a/test/MenuStyleTest.php +++ b/test/MenuStyleTest.php @@ -55,16 +55,6 @@ private function getMockTerminal() return $terminal; } - public function testMenuStyleCannotBeInstantiatedByDisallowedConsumers() - { - $this->setExpectedException( - InvalidInstantiationException::class, - 'The MenuStyle must be instantiated by "PhpSchool\CliMenu\CliMenuBuilder"' - ); - - new MenuStyle(); - } - public function testMenuStyleCanBeInstantiatedByCliMenuBuilder() { $builder = new CliMenuBuilder();