Completed
Push — develop ( 8eb671...133594 )
by Mike
19:30 queued 09:24
created

tests/features/bootstrap/Ast/UsesTagContext.php (1 issue)

parameters are used.

Unused Code Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 *  For the full copyright and license information, please view the LICENSE
6
 *  file that was distributed with this source code.
7
 *
8
 *  @copyright 2010-2018 Mike van Riel<[email protected]>
9
 *  @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 *  @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Behat\Contexts\Ast;
14
15
use Behat\Behat\Context\Context;
16
use Behat\Gherkin\Node\PyStringNode;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * This class contains the context methods for tests of the uses tag.
21
 */
22
final class UsesTagContext extends BaseContext implements Context
23
{
24
    /**
25
     * @param string $classFqsen
26
     * @throws Exception
27
     * @Then class ":classFqsen" has a tag uses referencing url ":reference"
28
     */
29
    public function classHasTagUsesReferencingUrl($classFqsen, $reference)
30
    {
31
        $class = $this->findClassByFqsen($classFqsen);
32
        $usesTags = $class->getTags()->get('uses', []);
33
        /** @var UsesTag $tag */
34
        foreach ($usesTags as $tag) {
35
            if (((string) $tag->getReference()) === $reference) {
36
                return;
37
            }
38
        }
39
40
        throw new \Exception(sprintf('Missing uses tag with reference "%s"', $reference));
41
    }
42
43
    /**
44
     * @param string $classFqsen
45
     * @Then class ":classFqsen" has :number tag/tags uses referencing :element descriptor ":reference"
46
     */
47
    public function classHasTagUsesReferencing($classFqsen, $number, $element, $reference)
48
    {
49
        $this->classHasTagUsesReferencingWithDescription($classFqsen, $number, $element, $reference, new PyStringNode([], 0));
50
    }
51
52
    /**
53
     * @param string $classFqsen
54
     * @throws Exception
55
     * @Then class ":classFqsen" has :number tag/tags uses referencing :element descriptor ":reference" with description:
56
     */
57
    public function classHasTagUsesReferencingWithDescription($classFqsen, $number, $element, $reference, PyStringNode $description)
0 ignored issues
show
The parameter $element is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        $count = 0;
60
        $class = $this->findClassByFqsen($classFqsen);
61
        $usesTags = $class->getTags()->get('uses', []);
62
        /** @var UsesTag $tag */
63
        foreach ($usesTags as $tag) {
64
            $r = (string) $tag->getReference();
65
            if ($r === $reference
66
                && ((string) $tag->getDescription()) === $description->getRaw()
67
            ) {
68
                ++$count;
69
            }
70
        }
71
72
        Assert::eq($number, $count, sprintf('Missing uses tag with reference "%s"', $reference));
73
    }
74
}
75