Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Utils
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
3 / 3
11
100.00% covered (success)
100.00%
1 / 1
 defineModelAnnotationsFromWsdl
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 getValidMetaValues
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
 getMetaValueAnnotation
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\File;
6
7use WsdlToPhp\PackageGenerator\Generator\Utils as GeneratorUtils;
8use WsdlToPhp\PackageGenerator\Model\AbstractModel;
9use WsdlToPhp\PhpGenerator\Element\PhpAnnotation;
10use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock;
11
12final class Utils
13{
14    public static function defineModelAnnotationsFromWsdl(PhpAnnotationBlock $block, AbstractModel $model, array $ignoreMeta = []): void
15    {
16        $validMeta = self::getValidMetaValues($model, $ignoreMeta);
17        if (!empty($validMeta)) {
18            // First line is the "The {propertyName}"
19            if (1 === count($block->getChildren())) {
20                $block->addChild('Meta information extracted from the WSDL');
21            }
22
23            foreach ($validMeta as $meta) {
24                $block->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, $meta, AbstractModelFile::ANNOTATION_META_LENGTH));
25            }
26        }
27    }
28
29    public static function getValidMetaValues(AbstractModel $model, array $ignoreMeta = []): array
30    {
31        $meta = $model->getMeta();
32        $validMeta = [];
33        foreach ($meta as $metaName => $metaValue) {
34            if (in_array($metaName, $ignoreMeta, true)) {
35                continue;
36            }
37
38            $finalMeta = self::getMetaValueAnnotation($metaName, $metaValue);
39            if (is_scalar($finalMeta)) {
40                $validMeta[] = $finalMeta;
41            }
42        }
43
44        return $validMeta;
45    }
46
47    public static function getMetaValueAnnotation(string $metaName, $metaValue): ?string
48    {
49        $meta = null;
50        if (is_array($metaValue)) {
51            $metaValue = implode(' | ', array_unique($metaValue));
52        }
53
54        $metaValue = GeneratorUtils::cleanComment($metaValue, ', ', false === mb_stripos($metaName, 'SOAPHeader'));
55        if (is_scalar($metaValue)) {
56            $meta = sprintf("\t- %s: %s", $metaName, $metaValue);
57        }
58
59        return $meta;
60    }
61}