Skip to content

Commit

Permalink
StaticClass: constructor is private [Closes nette/di#292]
Browse files Browse the repository at this point in the history
- ReflectionClass::isInstance() returns false
- it is marked as an error in the IDE
  • Loading branch information
dg committed Jan 17, 2024
1 parent a4175c6 commit b433959
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/StaticClass.php
Expand Up @@ -16,12 +16,10 @@
trait StaticClass
{
/**
* @return never
* @throws \Error
* Class is static and cannot be instantiated.
*/
final public function __construct()
private function __construct()
{
throw new \Error('Class ' . static::class . ' is static and cannot be instantiated.');
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/StaticClass.phpt
Expand Up @@ -22,7 +22,7 @@ class TestClass

Assert::exception(function () {
new TestClass;
}, Error::class, 'Class TestClass is static and cannot be instantiated.');
}, Error::class, 'Call to private TestClass::__construct() %a%');

Assert::exception(function () {
TestClass::methodA();
Expand Down

0 comments on commit b433959

Please sign in to comment.