| @@ 494-525 (lines=32) @@ | ||
| 491 | /** |
|
| 492 | * @return ClassGenerator |
|
| 493 | */ |
|
| 494 | public function generateMagicGet(): ClassGenerator |
|
| 495 | { |
|
| 496 | $cases = ''; |
|
| 497 | ||
| 498 | /** @var Property $property */ |
|
| 499 | foreach ($this->class->getProperties() as $property) { |
|
| 500 | $getter = static::camelCase('get_' . $property->getName()); |
|
| 501 | ||
| 502 | try { |
|
| 503 | $this->class->getMethod($getter); |
|
| 504 | } catch (InvalidArgumentException $e) { |
|
| 505 | continue; |
|
| 506 | } |
|
| 507 | ||
| 508 | $cases .= |
|
| 509 | ' case \'' . substr($property->getName(), 2, -2) . '\':' . PHP_EOL . |
|
| 510 | ' return $this->' . $getter . '();' . PHP_EOL . PHP_EOL; |
|
| 511 | } |
|
| 512 | ||
| 513 | $this->class |
|
| 514 | ->addMethod('__get') |
|
| 515 | ->addComment( |
|
| 516 | '@inheritDoc' |
|
| 517 | )->setBody( |
|
| 518 | 'switch ($name) {' . PHP_EOL . |
|
| 519 | $cases . |
|
| 520 | ' default:' . PHP_EOL . |
|
| 521 | ' return null;' . PHP_EOL . |
|
| 522 | '}' |
|
| 523 | )->addParameter('name'); |
|
| 524 | return $this; |
|
| 525 | } |
|
| 526 | ||
| 527 | /** |
|
| 528 | * @return ClassGenerator |
|
| @@ 571-602 (lines=32) @@ | ||
| 568 | /** |
|
| 569 | * @return ClassGenerator |
|
| 570 | */ |
|
| 571 | public function generateMagicIsset(): ClassGenerator |
|
| 572 | { |
|
| 573 | $cases = ''; |
|
| 574 | ||
| 575 | /** @var Property $property */ |
|
| 576 | foreach ($this->class->getProperties() as $property) { |
|
| 577 | $isset = static::camelCase('isset_' . $property->getName()); |
|
| 578 | ||
| 579 | try { |
|
| 580 | $this->class->getMethod($isset); |
|
| 581 | } catch (InvalidArgumentException $e) { |
|
| 582 | continue; |
|
| 583 | } |
|
| 584 | ||
| 585 | $cases .= |
|
| 586 | ' case \'' . substr($property->getName(), 2, -2) . '\':' . PHP_EOL . |
|
| 587 | ' return $this->' . $isset . '();' . PHP_EOL . PHP_EOL; |
|
| 588 | } |
|
| 589 | ||
| 590 | $this->class |
|
| 591 | ->addMethod('__isset') |
|
| 592 | ->addComment( |
|
| 593 | '@inheritDoc' |
|
| 594 | )->setBody( |
|
| 595 | 'switch ($name) {' . PHP_EOL . |
|
| 596 | $cases . |
|
| 597 | ' default:' . PHP_EOL . |
|
| 598 | ' return false;' . PHP_EOL . |
|
| 599 | '}' |
|
| 600 | )->addParameter('name'); |
|
| 601 | return $this; |
|
| 602 | } |
|
| 603 | ||
| 604 | /** |
|
| 605 | * @return ClassGenerator |
|
| @@ 607-638 (lines=32) @@ | ||
| 604 | /** |
|
| 605 | * @return ClassGenerator |
|
| 606 | */ |
|
| 607 | public function generateMagicUnset(): ClassGenerator |
|
| 608 | { |
|
| 609 | $cases = ''; |
|
| 610 | ||
| 611 | /** @var Property $property */ |
|
| 612 | foreach ($this->class->getProperties() as $property) { |
|
| 613 | $unset = static::camelCase('unset_' . $property->getName()); |
|
| 614 | ||
| 615 | try { |
|
| 616 | $this->class->getMethod($unset); |
|
| 617 | } catch (InvalidArgumentException $e) { |
|
| 618 | continue; |
|
| 619 | } |
|
| 620 | ||
| 621 | $cases .= |
|
| 622 | ' case \'' . substr($property->getName(), 2, -2) . '\':' . PHP_EOL . |
|
| 623 | ' return $this->' . $unset . '();' . PHP_EOL . PHP_EOL; |
|
| 624 | } |
|
| 625 | ||
| 626 | $this->class |
|
| 627 | ->addMethod('__unset') |
|
| 628 | ->addComment( |
|
| 629 | '@inheritDoc' |
|
| 630 | )->setBody( |
|
| 631 | 'switch ($name) {' . PHP_EOL . |
|
| 632 | $cases . |
|
| 633 | ' default:' . PHP_EOL . |
|
| 634 | ' return $this;' . PHP_EOL . |
|
| 635 | '}' |
|
| 636 | )->addParameter('name'); |
|
| 637 | return $this; |
|
| 638 | } |
|
| 639 | } |
|