GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( aeed96...e25155 )
by Malte
03:19
created

ShortcodeTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 13
eloc 33
c 5
b 0
f 0
dl 0
loc 105
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 3
A getRenderedExampleHtml() 0 3 1
A assertHttpStatusCodeWhenCrawlingRenderedExample() 0 8 1
A crawlRenderedExample() 0 15 2
A getCustomParametersAsString() 0 16 4
A getUrlWithRenderedExample() 0 10 2
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Tests\Functional;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Component\BrowserKit\Client;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\BrowserKit\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\DomCrawler\Crawler;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\DomCrawler\Crawler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * Abstract template for common shortcode tests.
11
 */
12
abstract class ShortcodeTest extends WebTestCase
13
{
14
    /** @var Client */
15
    protected $client;
16
17
    /**
18
     * @return string name of the shortcode to test.
19
     */
20
    abstract protected function getShortcodeToTest(): string;
21
22
    protected function setUp(): void
23
    {
24
        parent::setUp();
25
26
        if ('' === $this->getShortcodeToTest() || null === $this->getShortcodeToTest()) {
27
            throw new \PHPUnit_Framework_IncompleteTestError(
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_IncompleteTestError was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
                'Albeit being a '.__CLASS__.', '.\get_called_class().' does not define a shortcode to test.'
29
            );
30
        }
31
32
        static::bootKernel();
33
        $this->client = static::createClient();
34
    }
35
36
    /**
37
     * @param array|string|null $customParameters use of strings is deprecated, use array instead.
38
     *
39
     * @return Crawler
40
     */
41
    protected function getRenderedExampleHtml(?array $customParameters = null): string
42
    {
43
        return $this->crawlRenderedExample($customParameters)->html();
44
    }
45
46
    /**
47
     * @param array|string|null $customParameters use of strings is deprecated, use array instead.
48
     *
49
     * @return Crawler
50
     */
51
    protected function crawlRenderedExample(/*array*/ $customParameters = null): Crawler
52
    {
53
        $urlWithRenderedExample = $this->getUrlWithRenderedExample($customParameters);
54
55
        $crawlerOnRenderedExamplePage = $this->client->request('GET', $urlWithRenderedExample);
56
        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
57
58
        $crawlerOnRenderedExample = $crawlerOnRenderedExamplePage->filter('#rendered-example');
59
        if (0 === $crawlerOnRenderedExample->count()) {
60
            throw new \PHPUnit_Framework_ExpectationFailedException(
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_ExpectationFailedException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
                'No rendered example found for shortcode "'.$this->shortcode.'"'
0 ignored issues
show
Bug Best Practice introduced by
The property shortcode does not exist on Webfactory\ShortcodeBund...unctional\ShortcodeTest. Did you maybe forget to declare it?
Loading history...
62
            );
63
        }
64
65
        return $crawlerOnRenderedExample;
66
    }
67
68
    /**
69
     * @param int               $expectedStatusCode
70
     * @param array|string|null $customParameters   use of strings is deprecated, use array instead.
71
     *
72
     * @return Crawler
73
     */
74
    protected function assertHttpStatusCodeWhenCrawlingRenderedExample(
75
        int $expectedStatusCode,
76
        /*array*/ $customParameters = null
77
    ): Crawler {
78
        $urlWithRenderedExample = $this->getUrlWithRenderedExample($customParameters);
79
80
        $crawlerOnRenderedExamplePage = $this->client->request('GET', $urlWithRenderedExample);
0 ignored issues
show
Unused Code introduced by
The assignment to $crawlerOnRenderedExamplePage is dead and can be removed.
Loading history...
81
        $this->assertEquals($expectedStatusCode, $this->client->getResponse()->getStatusCode());
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Symfony\Component\DomCrawler\Crawler. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
82
    }
83
84
    /**
85
     * @param array|string|null $customParameters use of strings is deprecated, use array instead.
86
     *
87
     * @return Crawler
88
     */
89
    private function getUrlWithRenderedExample(/*array*/ $customParameters = null): string
90
    {
91
        $urlParameters = ['shortcode' => $this->getShortcodeToTest()];
92
93
        $customParametersAsString = $this->getCustomParametersAsString($customParameters);
94
        if ($customParametersAsString) {
95
            $urlParameters['customParameters'] = $customParametersAsString;
96
        }
97
98
        return static::$container->get('router')->generate('webfactory.shortcode.guide-detail', $urlParameters);
99
    }
100
101
    private function getCustomParametersAsString($customParametersAsMixed): ?string
102
    {
103
        if (\is_string($customParametersAsMixed)) {
104
            return $customParametersAsMixed;
105
        }
106
107
        if (\is_array($customParametersAsMixed)) {
108
            $customParametersAsString = '';
109
            foreach ($customParametersAsMixed as $name => $value) {
110
                $customParametersAsString .= $name.'='.$value.' ';
111
            }
112
113
            return $customParametersAsString;
114
        }
115
116
        return null;
117
    }
118
}
119