PhpstormMetaRenderer::render()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 1
1
<?php
2
/**
3
 * Spiral Framework, IDE Helper
4
 *
5
 * @author    Dmitry Mironov <[email protected]>
6
 * @licence   MIT
7
 */
8
9
namespace Spiral\IdeHelper\Renderer;
10
11
use Spiral\IdeHelper\Helpers;
12
use Spiral\IdeHelper\Model\ClassProperty;
13
14
/**
15
 * Class PhpstormMetaRenderer
16
 *
17
 * @package Spiral\IdeHelper\Renderer
18
 */
19
class PhpstormMetaRenderer implements RendererInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    private $method;
25
26
    /**
27
     * PhpstormMetaRenderer constructor.
28
     *
29
     * @param string $method
30
     */
31
    public function __construct(string $method = 'get')
32
    {
33
        $this->method = $method;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function render(array $classes): string
40
    {
41
        $content = '<?php' . PHP_EOL;
42
        $content .= 'namespace PHPSTORM_META {' . PHP_EOL;
43
44
        foreach ($classes as $class) {
45
            $target = $class->getName();
46
            $content .= "override(\\{$target}(0), map([" . PHP_EOL;
47
            foreach ($class->getMembers() as $member) {
48
                if ($member instanceof ClassProperty) {
49
                    $name = $member->getName();
50
                    $type = Helpers::fqcn($member->getTypes()[0]);
51
52
                    $content .= "'{$name}' => {$type}::class," . PHP_EOL;
53
                }
54
            }
55
            $content .= "]));" . PHP_EOL;
56
        }
57
58
        $content .= "}" . PHP_EOL;
59
60
        return $content;
61
    }
62
}
63