Skip to content
Permalink
Browse files

new deprecated stuff triggers warnings (BC break)

  • Loading branch information
dg committed Dec 21, 2016
1 parent 9dc4d48 commit b357b90beeed54e1e3f90c005c8e40240e4b1a36
@@ -68,6 +68,9 @@ class ClassType
*/
public static function from($class)
{
if ($class instanceof \ReflectionClass) {
trigger_error(__METHOD__ . '() accepts only class name or object.', E_USER_DEPRECATED);
}
return (new Factory)->fromClassReflection(
$class instanceof \ReflectionClass ? $class : new \ReflectionClass($class)
);
@@ -330,6 +333,7 @@ public function addTrait($trait, array $resolutions = [])
*/
public function setConsts(array $consts)
{
trigger_error(__METHOD__ . '() is deprecated, use setConstants()', E_USER_DEPRECATED);
return $this->setConstants($consts);
}

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

@@ -352,6 +357,7 @@ public function getConsts()
*/
public function addConst($name, $value)
{
trigger_error(__METHOD__ . '() is deprecated, use similar addConstant()', E_USER_DEPRECATED);
$this->addConstant($name, $value);
return $this;
}
@@ -41,7 +41,11 @@ class Method
*/
public static function from($method)
{
$method = $method instanceof \ReflectionMethod ? $method : Nette\Utils\Callback::toReflection($method);
if ($method instanceof \ReflectionMethod) {
trigger_error(__METHOD__ . '() accepts only method name.', E_USER_DEPRECATED);
} else {
$method = Nette\Utils\Callback::toReflection($method);
}
return (new Factory)->fromMethodReflection($method);
}

@@ -59,6 +59,7 @@ public function __construct($name = NULL)
/** @deprecated */
public function setName($name)
{
trigger_error(__METHOD__ . '() is deprecated, use constructor.', E_USER_DEPRECATED);
$this->__construct($name);
return $this;
}
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace Abc;

use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\Factory;
use Tester\Assert;


@@ -71,9 +72,9 @@ class Class3
$res[] = ClassType::from(Interface1::class);
$res[] = ClassType::from(Interface2::class);
$res[] = ClassType::from(Class1::class);
$res[] = ClassType::from(new \ReflectionClass(Class2::class));
$res[] = ClassType::from(new Class2);
$obj = new Class3;
$obj->prop2 = 1;
$res[] = ClassType::from(new \ReflectionObject($obj));
$res[] = (new Factory)->fromClassReflection(new \ReflectionObject($obj));

Assert::matchFile(__DIR__ . '/ClassType.from.expect', implode("\n", $res));
@@ -38,9 +38,9 @@ class Class2 extends Class1
{
}

$res[] = ClassType::from(new ReflectionClass('Trait1'));
$res[] = ClassType::from(new ReflectionClass('Trait2'));
$res[] = ClassType::from(new ReflectionClass('Class1'));
$res[] = ClassType::from(new ReflectionClass('Class2'));
$res[] = ClassType::from('Trait1');
$res[] = ClassType::from('Trait2');
$res[] = ClassType::from('Class1');
$res[] = ClassType::from('Class2');

Assert::matchFile(__DIR__ . '/ClassType.from.trait.expect', implode("\n", $res));
@@ -25,10 +25,8 @@ $class
->addTrait('AnotherTrait', ['sayHello as protected'])
->addComment("Description of class.\nThis is example\n")
->addComment('@property-read Nette\Forms\Form $form')
->setConsts(['ROLE' => 'admin'])
->addConst('ACTIVE', FALSE);

Assert::same(['ROLE' => 'admin', 'ACTIVE' => FALSE], $class->getConsts());
->setConstants(['ROLE' => 'admin'])
->addConstant('ACTIVE', FALSE);

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

0 comments on commit b357b90

Please sign in to comment.
You can’t perform that action at this time.