Issues (62)

src/NotFoundHttpHandler.php (6 issues)

1
<?php
2
3
namespace SMartins\JsonHandler;
4
5
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
0 ignored issues
show
The type Symfony\Component\HttpKe...n\NotFoundHttpException 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...
6
7
trait NotFoundHttpHandler
8
{
9
    /**
10
     * Set response parameters to NotFoundHttpException.
11
     *
12
     * @param  NotFoundHttpException $exception
13
     */
14
    public function notFoundHttpException(NotFoundHttpException $exception)
15
    {
16
        $statuCode = $exception->getStatusCode();
17
        $error = [[
18
            'status' => $statuCode,
19
            'code'   => $this->getCode('not_found_http'),
0 ignored issues
show
It seems like getCode() 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

19
            'code'   => $this->/** @scrutinizer ignore-call */ getCode('not_found_http'),
Loading history...
20
            'source' => ['pointer' => $exception->getFile().':'.$exception->getLine()],
21
            'title'  => $this->getDescription($exception),
0 ignored issues
show
It seems like getDescription() 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

21
            'title'  => $this->/** @scrutinizer ignore-call */ getDescription($exception),
Loading history...
22
            'detail' => $this->getNotFoundMessage($exception),
23
        ]];
24
25
        $this->jsonApiResponse->setStatus($statuCode);
0 ignored issues
show
Bug Best Practice introduced by
The property jsonApiResponse does not exist on SMartins\JsonHandler\NotFoundHttpHandler. Did you maybe forget to declare it?
Loading history...
26
        $this->jsonApiResponse->setErrors($error);
27
    }
28
29
    /**
30
     * Get message based on file. If file is RouteCollection return specific
31
     * message.
32
     *
33
     * @param  NotFoundHttpException $exception
34
     * @return string
35
     */
36
    public function getNotFoundMessage(NotFoundHttpException $exception)
37
    {
38
        $message = ! empty($exception->getMessage()) ? $exception->getMessage() : class_basename($exception);
0 ignored issues
show
The function class_basename 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

38
        $message = ! empty($exception->getMessage()) ? $exception->getMessage() : /** @scrutinizer ignore-call */ class_basename($exception);
Loading history...
39
        if (basename($exception->getFile()) === 'RouteCollection.php') {
40
            $message = __('exception::exceptions.not_found_http.message');
0 ignored issues
show
The function __ 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

40
            $message = /** @scrutinizer ignore-call */ __('exception::exceptions.not_found_http.message');
Loading history...
41
        }
42
43
        return $message;
44
    }
45
}
46