Passed
Push — master ( 5a03f9...8e29e6 )
by Stephen
03:56 queued 01:10
created

HttpResponses::successResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
4
namespace Sfneal\CrudModelActions\Utils;
5
6
7
trait HttpResponses
8
{
9
    /**
10
     * @var string Response to be returned on success
11
     */
12
    private $successResponse;
13
14
    /**
15
     * Return the default success response
16
     *
17
     * @param string|null $response
18
     * @return string
19
     */
20
    protected function successResponse(string $response = null): string
21
    {
22
        // Set the response during runtime
23
        if (isset($response)) {
24
            $this->successResponse = $response;
25
        }
26
27
        // Redirect back to previous page
28
        return $this->successResponse ?? redirect()->back();
29
    }
30
31
    /**
32
     * Return the default error response
33
     *
34
     * @return string
35
     */
36
    protected function failResponse(): string
37
    {
38
        // Return JS alert
39
        return jsAlert($this->failMessage());
0 ignored issues
show
Bug introduced by
It seems like failMessage() 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

39
        return jsAlert($this->/** @scrutinizer ignore-call */ failMessage());
Loading history...
Bug introduced by
The function jsAlert was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

39
        return /** @scrutinizer ignore-call */ jsAlert($this->failMessage());
Loading history...
40
    }
41
}
42