ErrorMessage   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 75 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 18
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 18 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Igorsgm\LaravelApiResponses\Macros;
4
5
use Igorsgm\LaravelApiResponses\ResponseMacroInterface;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Http\Response as HttpResponse;
8
use Illuminate\Routing\ResponseFactory;
9
10
class ErrorMessage implements ResponseMacroInterface
11
{
12
    /**
13
     * @param  ResponseFactory  $factory
14
     */
15 View Code Duplication
    public function run($factory)
16
    {
17
        $factory->macro('errorMessage',
18
            /**
19
             * Return an error JSON message from the application.
20
             * Called like: response()->successMessage(...)
21
             *
22
             * @param  string  $message
23
             * @param  int  $status
24
             * @param  array  $headers
25
             * @return JsonResponse
26
             */
27
            function ($message = '', $status = HttpResponse::HTTP_INTERNAL_SERVER_ERROR, array $headers = []) use (
28
                $factory
29
            ) {
30
                return $factory->error([], $message, $status, $headers);
31
            });
32
    }
33
}
34