Passed
Push — master ( dfab90...c365e9 )
by Divine Niiquaye
02:26
created

ParserException   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 21
ccs 0
cts 11
cp 0
rs 10
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B forTagWithParent() 0 19 9
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Biurad opensource projects.
7
 *
8
 * PHP version 7.2 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Biurad\UI\Exceptions;
19
20
class ParserException extends \ParseError
21
{
22
    public static function forTagWithParent(string $tagName, ?string $attrName = null, ?string $parent = null, bool $first = false, bool $void = false, bool $voidAttr = false): self
23
    {
24
        $errorMessage = 'Tag "%s" ' . (!empty($parent) ? ('must be inside a tag with attribute "%s"' . ($first ? ' as the first' : '')) : ('' === $parent ? $parent : 'is unexpected here'));
0 ignored issues
show
introduced by
The condition '' === $parent is always false.
Loading history...
25
        $errorArgs = [$tagName];
26
27
        if (null !== $attrName) {
28
            $errorMessage = \substr_replace($errorMessage, ' with attribute "%s"' . ($voidAttr ? ' expected no value' . (!empty($parent) ? ', and ' : ' ') : ' '), 8, 1);
29
            $errorArgs[] = $attrName;
30
        }
31
32
        if ($void) {
33
            $errorMessage .= ' and must be self closed.';
34
        }
35
36
        if (null !== $parent) {
37
            $errorArgs[] = $parent;
38
        }
39
40
        return new self(\vsprintf($errorMessage, $errorArgs));
0 ignored issues
show
Bug introduced by
It seems like $errorMessage can also be of type array; however, parameter $format of vsprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        return new self(\vsprintf(/** @scrutinizer ignore-type */ $errorMessage, $errorArgs));
Loading history...
41
    }
42
}
43