| @@ 505-536 (lines=32) @@ | ||
| 502 | /** |
|
| 503 | * @return ClassGenerator |
|
| 504 | */ |
|
| 505 | public function generateMagicGet(): ClassGenerator |
|
| 506 | { |
|
| 507 | $cases = ''; |
|
| 508 | ||
| 509 | /** @var Property $property */ |
|
| 510 | foreach ($this->class->getProperties() as $property) { |
|
| 511 | $getter = static::camelCase('get_' . $property->getName()); |
|
| 512 | ||
| 513 | try { |
|
| 514 | $this->class->getMethod($getter); |
|
| 515 | } catch (InvalidArgumentException $e) { |
|
| 516 | continue; |
|
| 517 | } |
|
| 518 | ||
| 519 | $cases .= |
|
| 520 | ' case \'' . substr($property->getName(), 2, -2) . '\':' . PHP_EOL . |
|
| 521 | ' return $this->' . $getter . '();' . PHP_EOL . PHP_EOL; |
|
| 522 | } |
|
| 523 | ||
| 524 | $this->class |
|
| 525 | ->addMethod('__get') |
|
| 526 | ->addComment( |
|
| 527 | '@inheritDoc' |
|
| 528 | )->setBody( |
|
| 529 | 'switch ($name) {' . PHP_EOL . |
|
| 530 | $cases . |
|
| 531 | ' default:' . PHP_EOL . |
|
| 532 | ' return null;' . PHP_EOL . |
|
| 533 | '}' |
|
| 534 | )->addParameter('name'); |
|
| 535 | return $this; |
|
| 536 | } |
|
| 537 | ||
| 538 | /** |
|
| 539 | * @return ClassGenerator |
|
| @@ 582-613 (lines=32) @@ | ||
| 579 | /** |
|
| 580 | * @return ClassGenerator |
|
| 581 | */ |
|
| 582 | public function generateMagicIsset(): ClassGenerator |
|
| 583 | { |
|
| 584 | $cases = ''; |
|
| 585 | ||
| 586 | /** @var Property $property */ |
|
| 587 | foreach ($this->class->getProperties() as $property) { |
|
| 588 | $isset = static::camelCase('isset_' . $property->getName()); |
|
| 589 | ||
| 590 | try { |
|
| 591 | $this->class->getMethod($isset); |
|
| 592 | } catch (InvalidArgumentException $e) { |
|
| 593 | continue; |
|
| 594 | } |
|
| 595 | ||
| 596 | $cases .= |
|
| 597 | ' case \'' . substr($property->getName(), 2, -2) . '\':' . PHP_EOL . |
|
| 598 | ' return $this->' . $isset . '();' . PHP_EOL . PHP_EOL; |
|
| 599 | } |
|
| 600 | ||
| 601 | $this->class |
|
| 602 | ->addMethod('__isset') |
|
| 603 | ->addComment( |
|
| 604 | '@inheritDoc' |
|
| 605 | )->setBody( |
|
| 606 | 'switch ($name) {' . PHP_EOL . |
|
| 607 | $cases . |
|
| 608 | ' default:' . PHP_EOL . |
|
| 609 | ' return false;' . PHP_EOL . |
|
| 610 | '}' |
|
| 611 | )->addParameter('name'); |
|
| 612 | return $this; |
|
| 613 | } |
|
| 614 | ||
| 615 | /** |
|
| 616 | * @return ClassGenerator |
|
| @@ 618-649 (lines=32) @@ | ||
| 615 | /** |
|
| 616 | * @return ClassGenerator |
|
| 617 | */ |
|
| 618 | public function generateMagicUnset(): ClassGenerator |
|
| 619 | { |
|
| 620 | $cases = ''; |
|
| 621 | ||
| 622 | /** @var Property $property */ |
|
| 623 | foreach ($this->class->getProperties() as $property) { |
|
| 624 | $unset = static::camelCase('unset_' . $property->getName()); |
|
| 625 | ||
| 626 | try { |
|
| 627 | $this->class->getMethod($unset); |
|
| 628 | } catch (InvalidArgumentException $e) { |
|
| 629 | continue; |
|
| 630 | } |
|
| 631 | ||
| 632 | $cases .= |
|
| 633 | ' case \'' . substr($property->getName(), 2, -2) . '\':' . PHP_EOL . |
|
| 634 | ' return $this->' . $unset . '();' . PHP_EOL . PHP_EOL; |
|
| 635 | } |
|
| 636 | ||
| 637 | $this->class |
|
| 638 | ->addMethod('__unset') |
|
| 639 | ->addComment( |
|
| 640 | '@inheritDoc' |
|
| 641 | )->setBody( |
|
| 642 | 'switch ($name) {' . PHP_EOL . |
|
| 643 | $cases . |
|
| 644 | ' default:' . PHP_EOL . |
|
| 645 | ' return $this;' . PHP_EOL . |
|
| 646 | '}' |
|
| 647 | )->addParameter('name'); |
|
| 648 | return $this; |
|
| 649 | } |
|
| 650 | } |
|