Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| XsdTypes | |
100.00% |
8 / 8 |
|
100.00% |
7 / 7 |
10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| instance | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDefaultConfigurationPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isXsd | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isAnonymous | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| phpType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |||
| parseXsdTypes | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WsdlToPhp\PackageGenerator\ConfigurationReader; |
| 6 | |
| 7 | final class XsdTypes extends AbstractYamlReader |
| 8 | { |
| 9 | public const MAIN_KEY = 'xsd_types'; |
| 10 | public const ANONYMOUS_KEY = 'anonymous'; |
| 11 | |
| 12 | /** |
| 13 | * This type is returned by the \SoapClient class when |
| 14 | * it does not succeed to define the type of a struct or an attribute. |
| 15 | */ |
| 16 | public const ANONYMOUS_TYPE = '/anonymous\d+/'; |
| 17 | |
| 18 | protected array $types = []; |
| 19 | |
| 20 | protected function __construct(string $filename) |
| 21 | { |
| 22 | $this->parseXsdTypes($filename); |
| 23 | } |
| 24 | |
| 25 | public static function instance(?string $filename = null): self |
| 26 | { |
| 27 | return parent::instance($filename); |
| 28 | } |
| 29 | |
| 30 | public static function getDefaultConfigurationPath(): string |
| 31 | { |
| 32 | return __DIR__.'/../resources/config/xsd_types.yml'; |
| 33 | } |
| 34 | |
| 35 | public function isXsd(string $xsdType): bool |
| 36 | { |
| 37 | return array_key_exists($xsdType, $this->types) || self::isAnonymous($xsdType); |
| 38 | } |
| 39 | |
| 40 | public static function isAnonymous(string $xsdType): bool |
| 41 | { |
| 42 | return (bool) preg_match(self::ANONYMOUS_TYPE, $xsdType); |
| 43 | } |
| 44 | |
| 45 | public function phpType(string $xsdType): string |
| 46 | { |
| 47 | return self::isAnonymous($xsdType) ? $this->types[self::ANONYMOUS_KEY] : ($this->isXsd($xsdType) ? $this->types[$xsdType] : ''); |
| 48 | } |
| 49 | |
| 50 | protected function parseXsdTypes(string $filename): self |
| 51 | { |
| 52 | $this->types = $this->parseSimpleArray($filename, self::MAIN_KEY); |
| 53 | |
| 54 | return $this; |
| 55 | } |
| 56 | } |