ClassCommentProcessor::addComment()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 2
b 0
f 0
nc 2
nop 3
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
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