MakesHttpRequests::call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 7
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 1
rs 9.9666
1
<?php
2
3
namespace Cerbero\OctaneTestbench\Concerns;
4
5
use Cerbero\OctaneTestbench\ResponseTestCase;
6
use Cerbero\OctaneTestbench\Stubs\ApplicationFactoryStub;
7
use Cerbero\OctaneTestbench\Stubs\ClientStub;
8
use Cerbero\OctaneTestbench\Stubs\WorkerStub;
9
use Illuminate\Http\Request;
10
use Laravel\Octane\Contracts\Client;
11
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
12
13
/**
14
 * The trait to make HTTP requests.
15
 *
16
 */
17
trait MakesHttpRequests
18
{
19
    /**
20
     * Call the given URI via Laravel Octane.
21
     *
22
     * @param string $method
23
     * @param string $uri
24
     * @param array $parameters
25
     * @param array $cookies
26
     * @param array $files
27
     * @param array $server
28
     * @param string|null $content
29
     * @return ResponseTestCase
30
     */
31 13
    public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
32
    {
33 13
        $request = SymfonyRequest::create(
34 13
            $this->prepareUrlForRequest($uri),
0 ignored issues
show
Bug introduced by
It seems like prepareUrlForRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

34
            $this->/** @scrutinizer ignore-call */ 
35
                   prepareUrlForRequest($uri),
Loading history...
35
            $method,
36
            $parameters,
37
            $cookies,
38 13
            array_merge($files, $this->extractFilesFromDataArray($parameters)),
0 ignored issues
show
Bug introduced by
It seems like extractFilesFromDataArray() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

38
            array_merge($files, $this->/** @scrutinizer ignore-call */ extractFilesFromDataArray($parameters)),
Loading history...
39 13
            array_replace($this->serverVariables, $server),
40
            $content,
41
        );
42
43 13
        return $this->sendToOctane(Request::createFromBase($request));
44
    }
45
46
    /**
47
     * Send a request to Laravel Octane.
48
     *
49
     * @param Request $request
50
     * @return ResponseTestCase
51
     */
52 13
    public function sendToOctane(Request $request): ResponseTestCase
53
    {
54 13
        $factory = new ApplicationFactoryStub($this->app);
55 13
        $client = new ClientStub($this);
0 ignored issues
show
Bug introduced by
$this of type Cerbero\OctaneTestbench\Concerns\MakesHttpRequests is incompatible with the type PHPUnit\Framework\TestCase expected by parameter $testCase of Cerbero\OctaneTestbench\...ientStub::__construct(). ( Ignorable by Annotation )

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

55
        $client = new ClientStub(/** @scrutinizer ignore-type */ $this);
Loading history...
56 13
        $worker = new WorkerStub($factory, $client);
57
58 13
        $this->app->instance(Client::class, $client);
59
60 13
        $worker->boot();
61
62 13
        return $worker->runRequest($request);
63
    }
64
}
65