Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2fc2add

Browse files
committed
ClassLike::from() & fromCode() returns 'static'
1 parent 7232944 commit 2fc2add

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

‎src/PhpGenerator/ClassLike.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,27 @@ abstract class ClassLike
3737
private ?string $name;
3838

3939

40-
public static function from(string|object $class, bool $withBodies = false): self
40+
public static function from(string|object $class, bool $withBodies = false): static
4141
{
4242
$instance = (new Factory)
4343
->fromClassReflection(new \ReflectionClass($class), $withBodies);
4444

4545
if (!$instance instanceof static) {
4646
$class = is_object($class) ? $class::class : $class;
47-
trigger_error("$class cannot be represented with " . static::class . '. Call ' . $instance::class . '::' . __FUNCTION__ . '() or ' . __METHOD__ . '() instead.', E_USER_WARNING);
47+
thrownewNette\InvalidArgumentException("$class cannot be represented with " . static::class . '. Call ' . $instance::class . '::' . __FUNCTION__ . '() or ' . __METHOD__ . '() instead.');
4848
}
4949

5050
return $instance;
5151
}
5252

5353

54-
public static function fromCode(string $code): self
54+
public static function fromCode(string $code): static
5555
{
5656
$instance = (new Factory)
5757
->fromClassCode($code);
5858

5959
if (!$instance instanceof static) {
60-
trigger_error('Provided code cannot be represented with ' . static::class . '. Call ' . $instance::class . '::' . __FUNCTION__ . '() or ' . __METHOD__ . '() instead.', E_USER_WARNING);
60+
thrownewNette\InvalidArgumentException('Provided code cannot be represented with ' . static::class . '. Call ' . $instance::class . '::' . __FUNCTION__ . '() or ' . __METHOD__ . '() instead.');
6161
}
6262

6363
return $instance;

‎tests/PhpGenerator/ClassLike.typecheck.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ require __DIR__ . '/../bootstrap.php';
1111
require __DIR__ . '/fixtures/classes.php';
1212

1313

14-
Assert::error(
14+
Assert::exception(
1515
fn() => ClassType::from(Abc\Interface1::class),
16-
E_USER_WARNING,
16+
Nette\InvalidArgumentException::class,
1717
'Abc\Interface1 cannot be represented with Nette\PhpGenerator\ClassType. Call Nette\PhpGenerator\InterfaceType::from() or Nette\PhpGenerator\ClassLike::from() instead.',
1818
);
1919

20-
Assert::error(
20+
Assert::exception(
2121
fn() => TraitType::from(Abc\Class1::class),
22-
E_USER_WARNING,
22+
Nette\InvalidArgumentException::class,
2323
'Abc\Class1 cannot be represented with Nette\PhpGenerator\TraitType. Call Nette\PhpGenerator\ClassType::from() or Nette\PhpGenerator\ClassLike::from() instead.',
2424
);
2525

26-
Assert::error(
26+
Assert::exception(
2727
fn() => ClassType::fromCode('<?php interface I {}'),
28-
E_USER_WARNING,
28+
Nette\InvalidArgumentException::class,
2929
'Provided code cannot be represented with Nette\PhpGenerator\ClassType. Call Nette\PhpGenerator\InterfaceType::fromCode() or Nette\PhpGenerator\ClassLike::fromCode() instead.',
3030
);
3131

32-
Assert::error(
32+
Assert::exception(
3333
fn() => InterfaceType::fromCode('<?php trait T {}'),
34-
E_USER_WARNING,
34+
Nette\InvalidArgumentException::class,
3535
'Provided code cannot be represented with Nette\PhpGenerator\InterfaceType. Call Nette\PhpGenerator\TraitType::fromCode() or Nette\PhpGenerator\ClassLike::fromCode() instead.',
3636
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /