Skip to content

Commit fe54e51

Browse files
committed
removed support for PHP 7
1 parent 0a2ef50 commit fe54e51

File tree

7 files changed

+18
-80
lines changed

7 files changed

+18
-80
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,7 @@ public function __construct(?string $name = null, ?PhpNamespace $namespace = nul
132132

133133
public function __toString(): string
134134
{
135-
try {
136-
return (new Printer)->printClass($this, $this->namespace);
137-
} catch (\Throwable $e) {
138-
if (PHP_VERSION_ID >= 70400) {
139-
throw $e;
140-
}
141-
142-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
143-
return '';
144-
}
135+
return (new Printer)->printClass($this, $this->namespace);
145136
}
146137

147138

src/PhpGenerator/Closure.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,7 @@ public static function from(\Closure $closure): self
3535

3636
public function __toString(): string
3737
{
38-
try {
39-
return (new Printer)->printClosure($this);
40-
} catch (\Throwable $e) {
41-
if (PHP_VERSION_ID >= 70400) {
42-
throw $e;
43-
}
44-
45-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
46-
return '';
47-
}
38+
return (new Printer)->printClosure($this);
4839
}
4940

5041

src/PhpGenerator/Factory.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function fromClassReflection(
7777

7878
if ($prop->isDefault()
7979
&& $declaringClass->name === $from->name
80-
&& (PHP_VERSION_ID < 80000 || !$prop->isPromoted())
80+
&& !$prop->isPromoted()
8181
&& !$class->isEnum()
8282
) {
8383
$props[] = $this->fromPropertyReflection($prop);
@@ -214,7 +214,7 @@ public function fromCallable(callable $from)
214214

215215
public function fromParameterReflection(\ReflectionParameter $from): Parameter
216216
{
217-
$param = PHP_VERSION_ID >= 80000 && $from->isPromoted()
217+
$param = $from->isPromoted()
218218
? new PromotedParameter($from->name)
219219
: new Parameter($from->name);
220220
$param->setReference($from->isPassedByReference());
@@ -279,23 +279,18 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
279279
$prop->setValue($defaults[$prop->getName()] ?? null);
280280
$prop->setStatic($from->isStatic());
281281
$prop->setVisibility($this->getVisibility($from));
282-
if (PHP_VERSION_ID >= 70400) {
283-
if ($from->getType() instanceof \ReflectionNamedType) {
284-
$prop->setType($from->getType()->getName());
285-
$prop->setNullable($from->getType()->allowsNull());
286-
} elseif (
287-
$from->getType() instanceof \ReflectionUnionType
288-
|| $from->getType() instanceof \ReflectionIntersectionType
289-
) {
290-
$prop->setType((string) $from->getType());
291-
}
292-
293-
$prop->setInitialized($from->hasType() && array_key_exists($prop->getName(), $defaults));
294-
$prop->setReadOnly(PHP_VERSION_ID >= 80100 ? $from->isReadOnly() : false);
295-
} else {
296-
$prop->setInitialized(false);
282+
if ($from->getType() instanceof \ReflectionNamedType) {
283+
$prop->setType($from->getType()->getName());
284+
$prop->setNullable($from->getType()->allowsNull());
285+
} elseif (
286+
$from->getType() instanceof \ReflectionUnionType
287+
|| $from->getType() instanceof \ReflectionIntersectionType
288+
) {
289+
$prop->setType((string) $from->getType());
297290
}
298291

292+
$prop->setInitialized($from->hasType() && array_key_exists($prop->getName(), $defaults));
293+
$prop->setReadOnly(PHP_VERSION_ID >= 80100 ? $from->isReadOnly() : false);
299294
$prop->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
300295
$prop->setAttributes(self::getAttributes($from));
301296
return $prop;
@@ -328,9 +323,6 @@ public function fromCode(string $code): PhpFile
328323

329324
private function getAttributes($from): array
330325
{
331-
if (PHP_VERSION_ID < 80000) {
332-
return [];
333-
}
334326

335327
return array_map(function ($attr) {
336328
$args = $attr->getArguments();

src/PhpGenerator/GlobalFunction.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ public static function withBodyFrom(string $function): self
3939

4040
public function __toString(): string
4141
{
42-
try {
43-
return (new Printer)->printFunction($this);
44-
} catch (\Throwable $e) {
45-
if (PHP_VERSION_ID >= 70400) {
46-
throw $e;
47-
}
48-
49-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
50-
return '';
51-
}
42+
return (new Printer)->printFunction($this);
5243
}
5344
}

src/PhpGenerator/Method.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@ public static function from($method): self
5050

5151
public function __toString(): string
5252
{
53-
try {
54-
return (new Printer)->printMethod($this);
55-
} catch (\Throwable $e) {
56-
if (PHP_VERSION_ID >= 70400) {
57-
throw $e;
58-
}
59-
60-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
61-
return '';
62-
}
53+
return (new Printer)->printMethod($this);
6354
}
6455

6556

src/PhpGenerator/PhpFile.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,6 @@ public function getStrictTypes(): bool
170170

171171
public function __toString(): string
172172
{
173-
try {
174-
return (new Printer)->printFile($this);
175-
} catch (\Throwable $e) {
176-
if (PHP_VERSION_ID >= 70400) {
177-
throw $e;
178-
}
179-
180-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
181-
return '';
182-
}
173+
return (new Printer)->printFile($this);
183174
}
184175
}

src/PhpGenerator/PhpNamespace.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,6 @@ private static function startsWith(string $a, string $b): bool
338338

339339
public function __toString(): string
340340
{
341-
try {
342-
return (new Printer)->printNamespace($this);
343-
} catch (\Throwable $e) {
344-
if (PHP_VERSION_ID >= 70400) {
345-
throw $e;
346-
}
347-
348-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
349-
return '';
350-
}
341+
return (new Printer)->printNamespace($this);
351342
}
352343
}

0 commit comments

Comments
 (0)