Passed
Branch 2.0 (f5ddb0)
by Samuel
04:04
created

AuthorizationHandler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMartins\Exceptions\Handlers;
4
5
use SMartins\Exceptions\JsonApi\Error;
6
use SMartins\Exceptions\JsonApi\Source;
7
8
class AuthorizationHandler extends AbstractHandler
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
13
    public function handle()
14
    {
15
        return (new Error)->setStatus(403)
0 ignored issues
show
Bug Best Practice introduced by
The expression return new SMartins\Exce...xception->getMessage()) returns the type SMartins\Exceptions\JsonApi\Error which is incompatible with the return type mandated by SMartins\Exceptions\Hand...stractHandler::handle() of array|Illuminate\Support\Collection.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
16
            ->setCode($this->getCode('authorization'))
17
            ->setSource((new Source())->setPointer($this->getDefaultPointer()))
18
            ->setTitle(__('exception::exceptions.authorization.title'))
19
            ->setDetail($this->exception->getMessage());
20
    }
21
}
22