Skip to content

Commit

Permalink
removed deprecated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 29, 2023
1 parent 663f6d1 commit d86fede
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 184 deletions.
14 changes: 1 addition & 13 deletions src/PhpGenerator/ClassLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,13 @@ abstract class ClassLike
private ?string $name;


public static function from(string|object $class, bool $withBodies = false, ?bool $materializeTraits = null): self
public static function from(string|object $class, bool $withBodies = false): self
{
if ($materializeTraits !== null) {
trigger_error(__METHOD__ . '() parameter $materializeTraits has been removed (is always false).', E_USER_DEPRECATED);
}
return (new Factory)
->fromClassReflection(new \ReflectionClass($class), $withBodies);
}


/** @deprecated use from(..., withBodies: true) */
public static function withBodiesFrom(string|object $class): self
{
trigger_error(__METHOD__ . '() is deprecated, use from(..., withBodies: true)', E_USER_DEPRECATED);
return (new Factory)
->fromClassReflection(new \ReflectionClass($class), withBodies: true);
}


public static function fromCode(string $code): self
{
return (new Factory)
Expand Down
41 changes: 0 additions & 41 deletions src/PhpGenerator/ClassType.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,65 +81,24 @@ public function __construct(?string $name = null, ?PhpNamespace $namespace = nul
}


/** @deprecated */
public function setClass(): static
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
$this->type = self::TYPE_CLASS;
return $this;
}


public function isClass(): bool
{
return $this->type === self::TYPE_CLASS;
}


/** @deprecated create object using 'new Nette\PhpGenerator\InterfaceType' */
public function setInterface(): static
{
trigger_error(__METHOD__ . "() is deprecated, create object using 'new Nette\\PhpGenerator\\InterfaceType'", E_USER_DEPRECATED);
$this->type = self::TYPE_INTERFACE;
return $this;
}


public function isInterface(): bool
{
return $this->type === self::TYPE_INTERFACE;
}


/** @deprecated create object using 'new Nette\PhpGenerator\TraitType' */
public function setTrait(): static
{
trigger_error(__METHOD__ . "() is deprecated, create object using 'new Nette\\PhpGenerator\\TraitType'", E_USER_DEPRECATED);
$this->type = self::TYPE_TRAIT;
return $this;
}


public function isTrait(): bool
{
return $this->type === self::TYPE_TRAIT;
}


/** @deprecated create object using 'new Nette\PhpGenerator\InterfaceType' or 'TraitType' */
public function setType(string $type): static
{
$upper = ucfirst($type);
trigger_error(__METHOD__ . "() is deprecated, create object using 'new Nette\\PhpGenerator\\{$upper}Type'", E_USER_DEPRECATED);
if (!in_array($type, [self::TYPE_CLASS, self::TYPE_INTERFACE, self::TYPE_TRAIT], true)) {
throw new Nette\InvalidArgumentException('Argument must be class|interface|trait.');
}

$this->type = $type;
return $this;
}


/** @deprecated */
public function getType(): string
{
Expand Down
4 changes: 0 additions & 4 deletions src/PhpGenerator/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ final class Factory
public function fromClassReflection(
\ReflectionClass $from,
bool $withBodies = false,
?bool $materializeTraits = null,
): ClassLike
{
if ($materializeTraits !== null) {
trigger_error(__METHOD__ . '() parameter $materializeTraits has been removed (is always false).', E_USER_DEPRECATED);
}
if ($withBodies && $from->isAnonymous()) {
throw new Nette\NotSupportedException('The $withBodies parameter cannot be used for anonymous functions.');
}
Expand Down
8 changes: 0 additions & 8 deletions src/PhpGenerator/GlobalFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ public static function from(string $function, bool $withBody = false): self
}


/** @deprecated use GlobalFunction::from(..., withBody: true) */
public static function withBodyFrom(string $function): self
{
trigger_error(__METHOD__ . '() is deprecated, use GlobalFunction::from(..., withBody: true)', E_USER_DEPRECATED);
return (new Factory)->fromFunctionReflection(new \ReflectionFunction($function), withBody: true);
}


public function __toString(): string
{
return (new Printer)->printFunction($this);
Expand Down
29 changes: 0 additions & 29 deletions src/PhpGenerator/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,6 @@ final class Helpers
'private' => 1, 'protected' => 1, 'public' => 1, 'readonly' => 1,
];

/** @deprecated */
public const
PHP_IDENT = self::ReIdentifier,
KEYWORDS = self::Keywords;


/** @deprecated use (new Nette\PhpGenerator\Dumper)->dump() */
public static function dump(mixed $var): string
{
trigger_error(__METHOD__ . '() is deprecated, use (new Nette\PhpGenerator\Dumper)->dump().', E_USER_DEPRECATED);
return (new Dumper)->dump($var);
}


/** @deprecated use (new Nette\PhpGenerator\Dumper)->format() */
public static function format(string $statement, mixed ...$args): string
{
trigger_error(__METHOD__ . '() is deprecated, use (new Nette\PhpGenerator\Dumper)->format().', E_USER_DEPRECATED);
return (new Dumper)->format($statement, ...$args);
}


/** @deprecated use (new Nette\PhpGenerator\Dumper)->format() */
public static function formatArgs(string $statement, array $args): string
{
trigger_error(__METHOD__ . '() is deprecated, use (new Nette\PhpGenerator\Dumper)->format().', E_USER_DEPRECATED);
return (new Dumper)->format($statement, ...$args);
}


public static function formatDocComment(string $content, bool $forceMultiLine = false): string
{
Expand Down
16 changes: 0 additions & 16 deletions src/PhpGenerator/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ public function getType(bool $asObject = false): Type|string|null
}


/** @deprecated use setType() */
public function setTypeHint(?string $type): static
{
trigger_error(__METHOD__ . '() is deprecated, use setType().', E_USER_DEPRECATED);
return $this->setType($type);
}


/** @deprecated use getType() */
public function getTypeHint(): ?string
{
trigger_error(__METHOD__ . '() is deprecated, use getType().', E_USER_DEPRECATED);
return $this->getType();
}


public function setNullable(bool $state = true): static
{
$this->nullable = $state;
Expand Down
8 changes: 0 additions & 8 deletions src/PhpGenerator/PhpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@ public function hasStrictTypes(): bool
}


/** @deprecated use hasStrictTypes() */
public function getStrictTypes(): bool
{
trigger_error(__METHOD__ . '() is deprecated, use hasStrictTypes().', E_USER_DEPRECATED);
return $this->strictTypes;
}


public function __toString(): string
{
return (new Printer)->printFile($this);
Expand Down
16 changes: 0 additions & 16 deletions src/PhpGenerator/PhpNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ public function hasBracketedSyntax(): bool
}


/** @deprecated use hasBracketedSyntax() */
public function getBracketedSyntax(): bool
{
trigger_error(__METHOD__ . '() is deprecated, use hasBracketedSyntax().', E_USER_DEPRECATED);
return $this->bracketedSyntax;
}


/**
* @throws InvalidStateException
*/
Expand Down Expand Up @@ -174,14 +166,6 @@ public function getUses(string $of = self::NameNormal): array
}


/** @deprecated use simplifyName() */
public function unresolveName(string $name): string
{
trigger_error(__METHOD__ . '() is deprecated, use simplifyName()', E_USER_DEPRECATED);
return $this->simplifyName($name);
}


public function resolveName(string $name, string $of = self::NameNormal): string
{
if (isset(Helpers::Keywords[strtolower($name)]) || $name === '') {
Expand Down
23 changes: 2 additions & 21 deletions src/PhpGenerator/TraitUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@
*/
final class TraitUse
{
use Nette\SmartObject {
__call as private parentCall;
}
use Nette\SmartObject;
use Traits\NameAware;
use Traits\CommentAware;

/** @var string[] */
private array $resolutions = [];
private ?ClassLike $parent;


public function __construct(string $name, ?ClassLike $parent = null)
public function __construct(string $name)
{
if (!Nette\PhpGenerator\Helpers::isNamespaceIdentifier($name, true)) {
throw new Nette\InvalidArgumentException("Value '$name' is not valid trait name.");
}

$this->name = $name;
$this->parent = $parent;
}


Expand All @@ -51,19 +47,4 @@ public function getResolutions(): array
{
return $this->resolutions;
}


/** @param mixed[] $args */
public function __call(string $nm, array $args): mixed
{
if (!$this->parent) {
return $this->parentCall($nm, $args);
}
$trace = debug_backtrace(0);
$loc = isset($trace[0]['file'])
? ' in ' . $trace[0]['file'] . ':' . $trace[0]['line']
: '';
trigger_error('The ClassType::addTrait() method now returns a TraitUse object instead of ClassType. Please fix the method chaining' . $loc, E_USER_DEPRECATED);
return $this->parent->$nm(...$args);
}
}
6 changes: 1 addition & 5 deletions src/PhpGenerator/Traits/ConstantsAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ trait ConstantsAware
/** @param Constant[] $consts */
public function setConstants(array $consts): static
{
(function (Constant ...$consts) {})(...$consts);
$this->consts = [];
foreach ($consts as $k => $const) {
if (!$const instanceof Constant) {
trigger_error(__METHOD__ . '() accepts an array of Constant as parameter, ' . get_debug_type($const) . ' given.', E_USER_DEPRECATED);
$const = (new Constant($k))->setValue($const)->setPublic();
}

$this->consts[$const->getName()] = $const;
}

Expand Down
8 changes: 0 additions & 8 deletions src/PhpGenerator/Traits/FunctionLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,4 @@ public function isReturnNullable(): bool
{
return $this->returnNullable;
}


/** @deprecated use isReturnNullable() */
public function getReturnNullable(): bool
{
trigger_error(__METHOD__ . '() is deprecated, use isReturnNullable().', E_USER_DEPRECATED);
return $this->returnNullable;
}
}
9 changes: 2 additions & 7 deletions src/PhpGenerator/Traits/TraitsAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ trait TraitsAware
/** @param TraitUse[] $traits */
public function setTraits(array $traits): static
{
(function (TraitUse|string ...$traits) {})(...$traits);
(function (TraitUse ...$traits) {})(...$traits);
$this->traits = [];
foreach ($traits as $trait) {
if (!$trait instanceof TraitUse) {
trigger_error(__METHOD__ . '() accepts an array of TraitUse as parameter, string given.', E_USER_DEPRECATED);
$trait = new TraitUse($trait);
}

$this->traits[$trait->getName()] = $trait;
}

Expand All @@ -52,7 +47,7 @@ public function addTrait(string $name, array|bool|null $deprecatedParam = null):
if (isset($this->traits[$name])) {
throw new Nette\InvalidStateException("Cannot add trait '$name', because it already exists.");
}
$this->traits[$name] = $trait = new TraitUse($name, $this);
$this->traits[$name] = $trait = new TraitUse($name);
if (is_array($deprecatedParam)) {
array_map(fn($item) => $trait->addResolution($item), $deprecatedParam);
}
Expand Down
8 changes: 0 additions & 8 deletions src/PhpGenerator/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,4 @@ public static function intersection(string ...$types): string
{
return implode('&', $types);
}


/** @deprecated use get_debug_type() */
public static function getType(mixed $value): ?string
{
trigger_error(__METHOD__ . '() is deprecated, use PHP function get_debug_type()', E_USER_DEPRECATED);
return is_resource($value) ? null : get_debug_type($value);
}
}

0 comments on commit d86fede

Please sign in to comment.