ClassCommentProcessor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 31
ccs 13
cts 13
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addComment() 0 5 2
A process() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Library\DTO\Preparation\Processor;
15
16
use Micro\Library\DTO\ClassDef\ClassDefinition;
17
use Micro\Library\DTO\Preparation\PreparationProcessorInterface;
18
19
class ClassCommentProcessor implements PreparationProcessorInterface
20
{
21 3
    public function process(iterable $classDef, ClassDefinition $classDefinition, array $classList): void
22
    {
23 3
        $opts = [
24 3
            self::DEPRECATED => '@deprecated',
25 3
            self::DESCRIPTION => null,
26 3
        ];
27
28 3
        foreach ($opts as $opt => $prefix) {
29 3
            $commentValue = $classDef[$opt] ?? false;
30 3
            if (!$commentValue) {
31 1
                continue;
32
            }
33
34 3
            $this->addComment($classDefinition, $commentValue, $prefix);
35
        }
36
    }
37
38
    /**
39
     * @param ClassDefinition $classDefinition
40
     * @param string          $comment
41
     * @param string|null     $commentPrefix
42
     *
43
     * @return void
44
     */
45 3
    protected function addComment(ClassDefinition $classDefinition, string $comment, ?string $commentPrefix): void
46
    {
47 3
        $text = $commentPrefix ? $commentPrefix.' '.$comment : $comment;
48
49 3
        $classDefinition->addComment($text);
50
    }
51
}
52