Skip to content

Commit b357b90

Browse files
committed
new deprecated stuff triggers warnings (BC break)
1 parent 9dc4d48 commit b357b90

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class ClassType
6868
*/
6969
public static function from($class)
7070
{
71+
if ($class instanceof \ReflectionClass) {
72+
trigger_error(__METHOD__ . '() accepts only class name or object.', E_USER_DEPRECATED);
73+
}
7174
return (new Factory)->fromClassReflection(
7275
$class instanceof \ReflectionClass ? $class : new \ReflectionClass($class)
7376
);
@@ -330,6 +333,7 @@ public function addTrait($trait, array $resolutions = [])
330333
*/
331334
public function setConsts(array $consts)
332335
{
336+
trigger_error(__METHOD__ . '() is deprecated, use setConstants()', E_USER_DEPRECATED);
333337
return $this->setConstants($consts);
334338
}
335339

@@ -340,6 +344,7 @@ public function setConsts(array $consts)
340344
*/
341345
public function getConsts()
342346
{
347+
trigger_error(__METHOD__ . '() is deprecated, use similar getConstants()', E_USER_DEPRECATED);
343348
return array_map(function ($const) { return $const->getValue(); }, $this->consts);
344349
}
345350

@@ -352,6 +357,7 @@ public function getConsts()
352357
*/
353358
public function addConst($name, $value)
354359
{
360+
trigger_error(__METHOD__ . '() is deprecated, use similar addConstant()', E_USER_DEPRECATED);
355361
$this->addConstant($name, $value);
356362
return $this;
357363
}

src/PhpGenerator/Method.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class Method
4141
*/
4242
public static function from($method)
4343
{
44-
$method = $method instanceof \ReflectionMethod ? $method : Nette\Utils\Callback::toReflection($method);
44+
if ($method instanceof \ReflectionMethod) {
45+
trigger_error(__METHOD__ . '() accepts only method name.', E_USER_DEPRECATED);
46+
} else {
47+
$method = Nette\Utils\Callback::toReflection($method);
48+
}
4549
return (new Factory)->fromMethodReflection($method);
4650
}
4751

src/PhpGenerator/PhpNamespace.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function __construct($name = NULL)
5959
/** @deprecated */
6060
public function setName($name)
6161
{
62+
trigger_error(__METHOD__ . '() is deprecated, use constructor.', E_USER_DEPRECATED);
6263
$this->__construct($name);
6364
return $this;
6465
}

tests/PhpGenerator/ClassType.from.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ declare(strict_types=1);
99
namespace Abc;
1010

1111
use Nette\PhpGenerator\ClassType;
12+
use Nette\PhpGenerator\Factory;
1213
use Tester\Assert;
1314

1415

@@ -71,9 +72,9 @@ class Class3
7172
$res[] = ClassType::from(Interface1::class);
7273
$res[] = ClassType::from(Interface2::class);
7374
$res[] = ClassType::from(Class1::class);
74-
$res[] = ClassType::from(new \ReflectionClass(Class2::class));
75+
$res[] = ClassType::from(new Class2);
7576
$obj = new Class3;
7677
$obj->prop2 = 1;
77-
$res[] = ClassType::from(new \ReflectionObject($obj));
78+
$res[] = (new Factory)->fromClassReflection(new \ReflectionObject($obj));
7879

7980
Assert::matchFile(__DIR__ . '/ClassType.from.expect', implode("\n", $res));

tests/PhpGenerator/ClassType.from.trait.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class Class2 extends Class1
3838
{
3939
}
4040

41-
$res[] = ClassType::from(new ReflectionClass('Trait1'));
42-
$res[] = ClassType::from(new ReflectionClass('Trait2'));
43-
$res[] = ClassType::from(new ReflectionClass('Class1'));
44-
$res[] = ClassType::from(new ReflectionClass('Class2'));
41+
$res[] = ClassType::from('Trait1');
42+
$res[] = ClassType::from('Trait2');
43+
$res[] = ClassType::from('Class1');
44+
$res[] = ClassType::from('Class2');
4545

4646
Assert::matchFile(__DIR__ . '/ClassType.from.trait.expect', implode("\n", $res));

tests/PhpGenerator/ClassType.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ $class
2525
->addTrait('AnotherTrait', ['sayHello as protected'])
2626
->addComment("Description of class.\nThis is example\n")
2727
->addComment('@property-read Nette\Forms\Form $form')
28-
->setConsts(['ROLE' => 'admin'])
29-
->addConst('ACTIVE', FALSE);
30-
31-
Assert::same(['ROLE' => 'admin', 'ACTIVE' => FALSE], $class->getConsts());
28+
->setConstants(['ROLE' => 'admin'])
29+
->addConstant('ACTIVE', FALSE);
3230

3331
$class->addConstant('FORCE_ARRAY', new PhpLiteral('Nette\Utils\Json::FORCE_ARRAY'))
3432
->setVisibility('private')

0 commit comments

Comments
 (0)