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.

assertHttpStatusCodeWhenCrawlingRenderedExample()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Tests\Functional;
4
5
use 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...
6
use 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...
7
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
8
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...
9
use Symfony\Component\DomCrawler\Crawler;
10
11
trigger_deprecation('webfactory/shortcode-bundle', '2.1.0', 'The '.ShortcodeTest::class.' class is deprecated without replacement; see the bundle README file for suggestions on how to test your shortcodes.');
12
13
/**
14
 * Abstract template for common shortcode tests.
15
 */
16
abstract class ShortcodeTest extends WebTestCase
17
{
18
    /** @var Client */
19
    protected $client;
20
21
    /**
22
     * @return string name of the shortcode to test.
23
     */
24
    abstract protected function getShortcodeToTest(): string;
25
26
    protected function setUp(): void
27
    {
28
        parent::setUp();
29
30
        if ('' === $this->getShortcodeToTest() || null === $this->getShortcodeToTest()) {
31
            throw new PHPUnit_Framework_IncompleteTestError('Albeit being a '.__CLASS__.', '.static::class.' does not define a shortcode to test.');
32
        }
33
34
        $this->client = static::createClient();
0 ignored issues
show
Documentation Bug introduced by
It seems like static::createClient() of type Symfony\Bundle\FrameworkBundle\KernelBrowser is incompatible with the declared type Symfony\Component\BrowserKit\Client of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
        static::bootKernel();
36
    }
37
38
    /**
39
     * @param array|string|null $customParameters use of strings is deprecated, use array instead.
40
     *
41
     * @return Crawler
42
     */
43
    protected function getRenderedExampleHtml(?array $customParameters = null): string
44
    {
45
        return $this->crawlRenderedExample($customParameters)->html();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->crawlRende...stomParameters)->html() returns the type string which is incompatible with the documented return type Symfony\Component\DomCrawler\Crawler.
Loading history...
46
    }
47
48
    /**
49
     * @param array|string|null $customParameters use of strings is deprecated, use array instead.
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('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...
61
        }
62
63
        return $crawlerOnRenderedExample;
64
    }
65
66
    /**
67
     * @param array|string|null $customParameters use of strings is deprecated, use array instead.
68
     */
69
    protected function assertHttpStatusCodeWhenCrawlingRenderedExample(
70
        int $expectedStatusCode,
71
        /* array */ $customParameters = null
72
    ): Crawler {
73
        $urlWithRenderedExample = $this->getUrlWithRenderedExample($customParameters);
74
75
        $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...
76
        $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...
77
    }
78
79
    /**
80
     * @param array|string|null $customParameters use of strings is deprecated, use array instead.
81
     *
82
     * @return Crawler
83
     */
84
    private function getUrlWithRenderedExample(/* array */ $customParameters = null): string
85
    {
86
        $urlParameters = ['shortcode' => $this->getShortcodeToTest()];
87
88
        $customParametersAsString = $this->getCustomParametersAsString($customParameters);
89
        if ($customParametersAsString) {
90
            $urlParameters['customParameters'] = $customParametersAsString;
91
        }
92
93
        return static::getContainer()->get('router')->generate('webfactory.shortcode.guide-detail', $urlParameters);
94
    }
95
96
    private function getCustomParametersAsString($customParametersAsMixed): ?string
97
    {
98
        if (\is_string($customParametersAsMixed)) {
99
            return $customParametersAsMixed;
100
        }
101
102
        if (\is_array($customParametersAsMixed)) {
103
            $customParametersAsString = '';
104
            foreach ($customParametersAsMixed as $name => $value) {
105
                $customParametersAsString .= $name.'='.$value.' ';
106
            }
107
108
            return $customParametersAsString;
109
        }
110
111
        return null;
112
    }
113
}
114