Skip to content

Commit 8af643b

Browse files
authored
Merge pull request #41 from php-school/remove-private-constructor
Remove instantiation restrictions
2 parents c7bdb1b + ee62e5e commit 8af643b

File tree

5 files changed

+0
-66
lines changed

5 files changed

+0
-66
lines changed

src/CliMenu.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class CliMenu
4949
*/
5050
protected $open = false;
5151

52-
/**
53-
* @var string
54-
*/
55-
private $allowedConsumer = 'PhpSchool\CliMenu\CliMenuBuilder';
56-
5752
/**
5853
* @var CliMenu|null
5954
*/
@@ -73,12 +68,6 @@ public function __construct(
7368
TerminalInterface $terminal = null,
7469
MenuStyle $style = null
7570
) {
76-
$builder = debug_backtrace();
77-
if (count($builder) < 2 || !isset($builder[1]['class']) || $builder[1]['class'] !== $this->allowedConsumer) {
78-
throw new InvalidInstantiationException(
79-
sprintf('The CliMenu must be instantiated by "%s"', $this->allowedConsumer)
80-
);
81-
}
8271

8372
$this->title = $title;
8473
$this->items = $items;

src/Exception/InvalidInstantiationException.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/MenuStyle.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ class MenuStyle
7676
*/
7777
private $titleSeparator;
7878

79-
/**
80-
* @var string
81-
*/
82-
private $allowedConsumer = 'PhpSchool\CliMenu\CliMenuBuilder';
83-
8479
/**
8580
* @var array
8681
*/
@@ -152,13 +147,6 @@ public function __construct(
152147
$titleSeparator = '=',
153148
TerminalInterface $terminal = null
154149
) {
155-
$builder = debug_backtrace();
156-
if (count($builder) < 2 || !isset($builder[1]['class']) || $builder[1]['class'] !== $this->allowedConsumer) {
157-
throw new InvalidInstantiationException(
158-
sprintf('The MenuStyle must be instantiated by "%s"', $this->allowedConsumer)
159-
);
160-
}
161-
162150
$this->terminal = $terminal ?: TerminalFactory::fromSystem();
163151
$this->bg = $bg;
164152
$this->fg = $fg;

test/Exception/InvalidInstantiationExceptionTest.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/MenuStyleTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ private function getMockTerminal()
5555
return $terminal;
5656
}
5757

58-
public function testMenuStyleCannotBeInstantiatedByDisallowedConsumers()
59-
{
60-
$this->setExpectedException(
61-
InvalidInstantiationException::class,
62-
'The MenuStyle must be instantiated by "PhpSchool\CliMenu\CliMenuBuilder"'
63-
);
64-
65-
new MenuStyle();
66-
}
67-
6858
public function testMenuStyleCanBeInstantiatedByCliMenuBuilder()
6959
{
7060
$builder = new CliMenuBuilder();

0 commit comments

Comments
 (0)