ErrorPresentationFactory   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 2
dl 0
loc 183
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 6 1
A badRequest() 0 6 1
A unauthorized() 0 6 1
A forbidden() 0 6 1
A notFound() 0 6 1
A conflict() 0 6 1
A gone() 0 6 1
A requestEntityToLarge() 0 6 1
A unsupportedMediaType() 0 6 1
A internalServerError() 0 6 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the FiveLab Resource package
7
 *
8
 * (c) FiveLab
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace FiveLab\Component\Resource\Resource\Error;
15
16
use FiveLab\Component\Resource\Presentation\PresentationFactory;
17
use FiveLab\Component\Resource\Presentation\PresentationInterface;
18
19
/**
20
 * The factory for easy create error presentation.
21
 *
22
 * @author Vitaliy Zhuk <[email protected]>
23
 */
24
class ErrorPresentationFactory
25
{
26
    /**
27
     * Create default error presentation.
28
     *
29
     * @param int         $statusCode
30
     * @param string      $message
31
     * @param string|null $reason
32
     * @param string|null $path
33
     * @param array       $attributes
34
     * @param string|int  $identifier
35
     *
36
     * @return PresentationInterface
37
     */
38 1
    public static function create(int $statusCode, string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
39
    {
40 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
41
42 1
        return PresentationFactory::create($statusCode, $error);
43
    }
44
45
    /**
46
     * Create the bad request error presentation.
47
     *
48
     * @param string     $message
49
     * @param string     $reason
50
     * @param string     $path
51
     * @param array      $attributes
52
     * @param string|int $identifier
53
     *
54
     * @return PresentationInterface
55
     */
56 1
    public static function badRequest(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
57
    {
58 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
59
60 1
        return PresentationFactory::badRequest($error);
61
    }
62
63
    /**
64
     * Create the unauthorized error presentation.
65
     *
66
     * @param string     $message
67
     * @param string     $reason
68
     * @param string     $path
69
     * @param array      $attributes
70
     * @param string|int $identifier
71
     *
72
     * @return PresentationInterface
73
     */
74 1
    public static function unauthorized(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
75
    {
76 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
77
78 1
        return PresentationFactory::unauthorized($error);
79
    }
80
81
    /**
82
     * Create the forbidden error presentation.
83
     *
84
     * @param string     $message
85
     * @param string     $reason
86
     * @param string     $path
87
     * @param array      $attributes
88
     * @param string|int $identifier
89
     *
90
     * @return PresentationInterface
91
     */
92 1
    public static function forbidden(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
93
    {
94 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
95
96 1
        return PresentationFactory::forbidden($error);
97
    }
98
99
    /**
100
     * Create the not found error presentation.
101
     *
102
     * @param string     $message
103
     * @param string     $reason
104
     * @param string     $path
105
     * @param array      $attributes
106
     * @param string|int $identifier
107
     *
108
     * @return PresentationInterface
109
     */
110 1
    public static function notFound(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
111
    {
112 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
113
114 1
        return PresentationFactory::notFound($error);
115
    }
116
117
    /**
118
     * Create the conflict error presentation.
119
     *
120
     * @param string     $message
121
     * @param string     $reason
122
     * @param string     $path
123
     * @param array      $attributes
124
     * @param string|int $identifier
125
     *
126
     * @return PresentationInterface
127
     */
128 1
    public static function conflict(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
129
    {
130 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
131
132 1
        return PresentationFactory::conflict($error);
133
    }
134
135
    /**
136
     * Create the gone error presentation.
137
     *
138
     * @param string     $message
139
     * @param string     $reason
140
     * @param string     $path
141
     * @param array      $attributes
142
     * @param string|int $identifier
143
     *
144
     * @return PresentationInterface
145
     */
146 1
    public static function gone(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
147
    {
148 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
149
150 1
        return PresentationFactory::gone($error);
151
    }
152
153
    /**
154
     * Create the request entity to large error presentation.
155
     *
156
     * @param string     $message
157
     * @param string     $reason
158
     * @param string     $path
159
     * @param array      $attributes
160
     * @param string|int $identifier
161
     *
162
     * @return PresentationInterface
163
     */
164 1
    public static function requestEntityToLarge(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
165
    {
166 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
167
168 1
        return PresentationFactory::requestEntityToLarge($error);
169
    }
170
171
    /**
172
     * Create the unsupported media type error presentation.
173
     *
174
     * @param string     $message
175
     * @param string     $reason
176
     * @param string     $path
177
     * @param array      $attributes
178
     * @param string|int $identifier
179
     *
180
     * @return PresentationInterface
181
     */
182 1
    public static function unsupportedMediaType(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
183
    {
184 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
185
186 1
        return PresentationFactory::unsupportedMediaType($error);
187
    }
188
189
    /**
190
     * Create the internal server error presentation.
191
     *
192
     * @param string     $message
193
     * @param string     $reason
194
     * @param string     $path
195
     * @param array      $attributes
196
     * @param string|int $identifier
197
     *
198
     * @return PresentationInterface
199
     */
200 1
    public static function internalServerError(string $message, $reason = null, string $path = null, array $attributes = [], $identifier = null): PresentationInterface
201
    {
202 1
        $error = new ErrorResource($message, $reason, $path, $attributes, $identifier);
203
204 1
        return PresentationFactory::internalServerError($error);
205
    }
206
}
207