Issues (5)

src/PayloadFactory.php (4 issues)

1
<?php
2
namespace RazonYang\JSend;
3
4
/**
5
 * MessageFactory is a factory that provides shortcuts to generate message.
6
 */
7
class PayloadFactory
8
{
9
    /**
10
     * Generates success payload.
11
     *
12
     * @param mixed $data
13
     *
14
     * @return MessageInterface
0 ignored issues
show
The type RazonYang\JSend\MessageInterface 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...
15
     */
16 3
    public static function success($data): PayloadInterface
17
    {
18 3
        return (new Payload())
0 ignored issues
show
Bug Best Practice introduced by
The expression return new RazonYang\JSe...UCCESS)->setData($data) returns the type RazonYang\JSend\Payload which is incompatible with the documented return type RazonYang\JSend\MessageInterface.
Loading history...
19 3
            ->setStatus(Status::SUCCESS)
20 3
            ->setData($data);
21
    }
22
23
    /**
24
     * Generates fail payload.
25
     *
26
     * @param mixed $data
27
     *
28
     * @return MessageInterface
29
     */
30 3
    public static function fail($data): PayloadInterface
31
    {
32 3
        return (new Payload())
0 ignored issues
show
Bug Best Practice introduced by
The expression return new RazonYang\JSe...::FAIL)->setData($data) returns the type RazonYang\JSend\Payload which is incompatible with the documented return type RazonYang\JSend\MessageInterface.
Loading history...
33 3
            ->setStatus(Status::FAIL)
34 3
            ->setData($data);
35
    }
36
37
    /**
38
     * Generates error payload.
39
     *
40
     * @param mixed $data
41
     *
42
     * @param string $message error message.
43
     * @param int    $code    error code.
44
     * @param mixed  $data    error data, i.e. stack traces.
45
     *
46
     * @return MessageInterface
47
     */
48 3
    public static function error(string $message, ?int $code = null, $data = null): PayloadInterface
49
    {
50 3
        $payload = (new Payload())
51 3
            ->setStatus(Status::ERROR)
52 3
            ->setMessage($message);
53 3
        if ($code !== null) {
54 2
            $payload->setCode($code);
55
        }
56 3
        if ($data !== null) {
57 1
            $payload->setData($data);
58
        }
59
        
60 3
        return $payload;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $payload returns the type RazonYang\JSend\Payload which is incompatible with the documented return type RazonYang\JSend\MessageInterface.
Loading history...
61
    }
62
}
63