This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace App\Exceptions; |
||
4 | |||
5 | // controller |
||
6 | use Bugsnag; |
||
7 | //use Illuminate\Validation\ValidationException; |
||
8 | use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler; |
||
9 | use Exception; |
||
10 | use Illuminate\Auth\Access\AuthorizationException; |
||
11 | // use Symfony\Component\HttpKernel\Exception\HttpException; |
||
12 | // use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||
13 | use Illuminate\Database\Eloquent\ModelNotFoundException; |
||
14 | use Illuminate\Foundation\Validation\ValidationException; |
||
15 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
16 | |||
17 | class Handler extends ExceptionHandler |
||
18 | { |
||
19 | /** |
||
20 | * A list of the exception types that should not be reported. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $dontReport = [ |
||
25 | // 'Symfony\Component\HttpKernel\Exception\HttpException', |
||
26 | \Illuminate\Http\Exception\HttpResponseException::class, |
||
27 | ValidationException::class, |
||
28 | AuthorizationException::class, |
||
29 | HttpResponseException ::class, |
||
30 | ModelNotFoundException::class, |
||
31 | \Symfony\Component\HttpKernel\Exception\HttpException::class, |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * Report or log an exception. |
||
36 | * |
||
37 | * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
||
38 | * |
||
39 | * @param \Exception $e |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function report(Exception $e) |
||
44 | { |
||
45 | $debug = \Config::get('app.bugsnag_reporting'); |
||
46 | $debug = ($debug) ? 'true' : 'false'; |
||
47 | if ($debug == 'false') { |
||
48 | Bugsnag::setBeforeNotifyFunction(function ($error) { |
||
0 ignored issues
–
show
|
|||
49 | return false; |
||
50 | }); |
||
51 | } else { |
||
52 | $version = \Config::get('app.version'); |
||
53 | Bugsnag::setAppVersion($version); |
||
54 | } |
||
55 | |||
56 | return parent::report($e); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Render an exception into an HTTP response. |
||
61 | * |
||
62 | * @param type $request |
||
63 | * @param Exception $e |
||
64 | * |
||
65 | * @return type mixed |
||
66 | */ |
||
67 | public function render($request, Exception $e) |
||
68 | { |
||
69 | switch ($e) { |
||
70 | case $e instanceof \Illuminate\Http\Exception\HttpResponseException: |
||
71 | return parent::render($request, $e); |
||
0 ignored issues
–
show
The return type of
return parent::render($request, $e); (Symfony\Component\HttpFoundation\Response ) is incompatible with the return type documented by App\Exceptions\Handler::render of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
72 | View Code Duplication | case $e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException: |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
73 | return response()->json(['message' => $e->getMessage(), 'code' => $e->getStatusCode()]); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Exception as the method getStatusCode() does only exist in the following sub-classes of Exception : Aws\Acm\Exception\AcmException , Aws\ApiGateway\Exception\ApiGatewayException , Aws\ApplicationAutoScali...ionAutoScalingException , Aws\ApplicationDiscovery...scoveryServiceException , Aws\AutoScaling\Exception\AutoScalingException , Aws\CloudFormation\Excep...CloudFormationException , Aws\CloudFront\Exception\CloudFrontException , Aws\CloudHsm\Exception\CloudHsmException , Aws\CloudSearchDomain\Ex...udSearchDomainException , Aws\CloudSearch\Exception\CloudSearchException , Aws\CloudTrail\Exception\CloudTrailException , Aws\CloudWatchEvents\Exc...oudWatchEventsException , Aws\CloudWatchLogs\Excep...CloudWatchLogsException , Aws\CloudWatch\Exception\CloudWatchException , Aws\CodeCommit\Exception\CodeCommitException , Aws\CodeDeploy\Exception\CodeDeployException , Aws\CodePipeline\Exception\CodePipelineException , Aws\CognitoIdentityProvi...entityProviderException , Aws\CognitoIdentity\Exce...ognitoIdentityException , Aws\CognitoSync\Exception\CognitoSyncException , Aws\ConfigService\Exception\ConfigServiceException , Aws\DataPipeline\Exception\DataPipelineException , Aws\DatabaseMigrationSer...grationServiceException , Aws\DeviceFarm\Exception\DeviceFarmException , Aws\DirectConnect\Exception\DirectConnectException , Aws\DirectoryService\Exc...rectoryServiceException , Aws\DynamoDbStreams\Exce...ynamoDbStreamsException , Aws\DynamoDb\Exception\DynamoDbException , Aws\Ec2\Exception\Ec2Exception , Aws\Ecr\Exception\EcrException , Aws\Ecs\Exception\EcsException , Aws\Efs\Exception\EfsException , Aws\ElastiCache\Exception\ElastiCacheException , Aws\ElasticBeanstalk\Exc...asticBeanstalkException , Aws\ElasticLoadBalancing...oadBalancingV2Exception , Aws\ElasticLoadBalancing...cLoadBalancingException , Aws\ElasticTranscoder\Ex...sticTranscoderException , Aws\ElasticsearchService...csearchServiceException , Aws\Emr\Exception\EmrException , Aws\Exception\AwsException , Aws\Firehose\Exception\FirehoseException , Aws\GameLift\Exception\GameLiftException , Aws\Glacier\Exception\GlacierException , Aws\Iam\Exception\IamException , Aws\ImportExport\Exception\ImportExportException , Aws\Inspector\Exception\InspectorException , Aws\IotDataPlane\Exception\IotDataPlaneException , Aws\Iot\Exception\IotException , Aws\KinesisAnalytics\Exc...nesisAnalyticsException , Aws\Kinesis\Exception\KinesisException , Aws\Kms\Exception\KmsException , Aws\Lambda\Exception\LambdaException , Aws\MachineLearning\Exce...achineLearningException , Aws\MarketplaceCommerceA...merceAnalyticsException , Aws\MarketplaceMetering\...tplaceMeteringException , Aws\OpsWorks\Exception\OpsWorksException , Aws\Rds\Exception\RdsException , Aws\Redshift\Exception\RedshiftException , Aws\Route53Domains\Excep...Route53DomainsException , Aws\Route53\Exception\Route53Exception , Aws\S3\Exception\PermanentRedirectException , Aws\S3\Exception\S3Exception , Aws\ServiceCatalog\Excep...ServiceCatalogException , Aws\Ses\Exception\SesException , Aws\SnowBall\Exception\SnowBallException , Aws\Sns\Exception\SnsException , Aws\Sqs\Exception\SqsException , Aws\Ssm\Exception\SsmException , Aws\StorageGateway\Excep...StorageGatewayException , Aws\Sts\Exception\StsException , Aws\Support\Exception\SupportException , Aws\Swf\Exception\SwfException , Aws\Waf\Exception\WafException , Aws\WorkSpaces\Exception\WorkSpacesException , Symfony\Component\HttpKe...cessDeniedHttpException , Symfony\Component\HttpKe...BadRequestHttpException , Symfony\Component\HttpKe...n\ConflictHttpException , Symfony\Component\HttpKe...ption\GoneHttpException , Symfony\Component\HttpKe...Exception\HttpException , Symfony\Component\HttpKe...thRequiredHttpException , Symfony\Component\HttpKe...NotAllowedHttpException , Symfony\Component\HttpKe...AcceptableHttpException , Symfony\Component\HttpKe...n\NotFoundHttpException , Symfony\Component\HttpKe...tionFailedHttpException , Symfony\Component\HttpKe...onRequiredHttpException , Symfony\Component\HttpKe...navailableHttpException , Symfony\Component\HttpKe...nyRequestsHttpException , Symfony\Component\HttpKe...authorizedHttpException , Symfony\Component\HttpKe...ableEntityHttpException , Symfony\Component\HttpKe...dMediaTypeHttpException , Tymon\JWTAuth\Exceptions\InvalidClaimException , Tymon\JWTAuth\Exceptions\JWTException , Tymon\JWTAuth\Exceptions\PayloadException , Tymon\JWTAuth\Exceptions\TokenBlacklistedException , Tymon\JWTAuth\Exceptions\TokenExpiredException , Tymon\JWTAuth\Exceptions\TokenInvalidException . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() The return type of
return response()->json(... $e->getStatusCode())); (Illuminate\Http\JsonResponse ) is incompatible with the return type documented by App\Exceptions\Handler::render of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
74 | View Code Duplication | case $e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException: |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
75 | return response()->json(['message' => $e->getMessage(), 'code' => $e->getStatusCode()]); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Exception as the method getStatusCode() does only exist in the following sub-classes of Exception : Aws\Acm\Exception\AcmException , Aws\ApiGateway\Exception\ApiGatewayException , Aws\ApplicationAutoScali...ionAutoScalingException , Aws\ApplicationDiscovery...scoveryServiceException , Aws\AutoScaling\Exception\AutoScalingException , Aws\CloudFormation\Excep...CloudFormationException , Aws\CloudFront\Exception\CloudFrontException , Aws\CloudHsm\Exception\CloudHsmException , Aws\CloudSearchDomain\Ex...udSearchDomainException , Aws\CloudSearch\Exception\CloudSearchException , Aws\CloudTrail\Exception\CloudTrailException , Aws\CloudWatchEvents\Exc...oudWatchEventsException , Aws\CloudWatchLogs\Excep...CloudWatchLogsException , Aws\CloudWatch\Exception\CloudWatchException , Aws\CodeCommit\Exception\CodeCommitException , Aws\CodeDeploy\Exception\CodeDeployException , Aws\CodePipeline\Exception\CodePipelineException , Aws\CognitoIdentityProvi...entityProviderException , Aws\CognitoIdentity\Exce...ognitoIdentityException , Aws\CognitoSync\Exception\CognitoSyncException , Aws\ConfigService\Exception\ConfigServiceException , Aws\DataPipeline\Exception\DataPipelineException , Aws\DatabaseMigrationSer...grationServiceException , Aws\DeviceFarm\Exception\DeviceFarmException , Aws\DirectConnect\Exception\DirectConnectException , Aws\DirectoryService\Exc...rectoryServiceException , Aws\DynamoDbStreams\Exce...ynamoDbStreamsException , Aws\DynamoDb\Exception\DynamoDbException , Aws\Ec2\Exception\Ec2Exception , Aws\Ecr\Exception\EcrException , Aws\Ecs\Exception\EcsException , Aws\Efs\Exception\EfsException , Aws\ElastiCache\Exception\ElastiCacheException , Aws\ElasticBeanstalk\Exc...asticBeanstalkException , Aws\ElasticLoadBalancing...oadBalancingV2Exception , Aws\ElasticLoadBalancing...cLoadBalancingException , Aws\ElasticTranscoder\Ex...sticTranscoderException , Aws\ElasticsearchService...csearchServiceException , Aws\Emr\Exception\EmrException , Aws\Exception\AwsException , Aws\Firehose\Exception\FirehoseException , Aws\GameLift\Exception\GameLiftException , Aws\Glacier\Exception\GlacierException , Aws\Iam\Exception\IamException , Aws\ImportExport\Exception\ImportExportException , Aws\Inspector\Exception\InspectorException , Aws\IotDataPlane\Exception\IotDataPlaneException , Aws\Iot\Exception\IotException , Aws\KinesisAnalytics\Exc...nesisAnalyticsException , Aws\Kinesis\Exception\KinesisException , Aws\Kms\Exception\KmsException , Aws\Lambda\Exception\LambdaException , Aws\MachineLearning\Exce...achineLearningException , Aws\MarketplaceCommerceA...merceAnalyticsException , Aws\MarketplaceMetering\...tplaceMeteringException , Aws\OpsWorks\Exception\OpsWorksException , Aws\Rds\Exception\RdsException , Aws\Redshift\Exception\RedshiftException , Aws\Route53Domains\Excep...Route53DomainsException , Aws\Route53\Exception\Route53Exception , Aws\S3\Exception\PermanentRedirectException , Aws\S3\Exception\S3Exception , Aws\ServiceCatalog\Excep...ServiceCatalogException , Aws\Ses\Exception\SesException , Aws\SnowBall\Exception\SnowBallException , Aws\Sns\Exception\SnsException , Aws\Sqs\Exception\SqsException , Aws\Ssm\Exception\SsmException , Aws\StorageGateway\Excep...StorageGatewayException , Aws\Sts\Exception\StsException , Aws\Support\Exception\SupportException , Aws\Swf\Exception\SwfException , Aws\Waf\Exception\WafException , Aws\WorkSpaces\Exception\WorkSpacesException , Symfony\Component\HttpKe...cessDeniedHttpException , Symfony\Component\HttpKe...BadRequestHttpException , Symfony\Component\HttpKe...n\ConflictHttpException , Symfony\Component\HttpKe...ption\GoneHttpException , Symfony\Component\HttpKe...Exception\HttpException , Symfony\Component\HttpKe...thRequiredHttpException , Symfony\Component\HttpKe...NotAllowedHttpException , Symfony\Component\HttpKe...AcceptableHttpException , Symfony\Component\HttpKe...n\NotFoundHttpException , Symfony\Component\HttpKe...tionFailedHttpException , Symfony\Component\HttpKe...onRequiredHttpException , Symfony\Component\HttpKe...navailableHttpException , Symfony\Component\HttpKe...nyRequestsHttpException , Symfony\Component\HttpKe...authorizedHttpException , Symfony\Component\HttpKe...ableEntityHttpException , Symfony\Component\HttpKe...dMediaTypeHttpException , Tymon\JWTAuth\Exceptions\InvalidClaimException , Tymon\JWTAuth\Exceptions\JWTException , Tymon\JWTAuth\Exceptions\PayloadException , Tymon\JWTAuth\Exceptions\TokenBlacklistedException , Tymon\JWTAuth\Exceptions\TokenExpiredException , Tymon\JWTAuth\Exceptions\TokenInvalidException . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() The return type of
return response()->json(... $e->getStatusCode())); (Illuminate\Http\JsonResponse ) is incompatible with the return type documented by App\Exceptions\Handler::render of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
76 | default: |
||
77 | return $this->common($request, $e); |
||
0 ignored issues
–
show
$e is of type object<Exception> , but the function expects a object<App\Exceptions\type> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() The return type of
return $this->common($request, $e); (App\Exceptions\type ) is incompatible with the return type declared by the interface Illuminate\Contracts\Deb...xceptionHandler::render of type Symfony\Component\HttpFoundation\Response .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
78 | } |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Function to render 500 error page. |
||
83 | * |
||
84 | * @param type $request |
||
85 | * @param type $e |
||
86 | * |
||
87 | * @return type mixed |
||
88 | */ |
||
89 | public function render500($request, $e) |
||
90 | { |
||
91 | if (config('app.debug') == true) { |
||
92 | return parent::render($request, $e); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
render() instead of render500() ). Are you sure this is correct? If so, you might want to change this to $this->render() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
93 | } elseif ($e instanceof ValidationException) { |
||
94 | return parent::render($request, $e); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
render() instead of render500() ). Are you sure this is correct? If so, you might want to change this to $this->render() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
95 | } |
||
96 | |||
97 | return response()->view('errors.500'); |
||
98 | //return redirect()->route('error500', []); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
74% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Function to render 404 error page. |
||
103 | * |
||
104 | * @param type $request |
||
105 | * @param type $e |
||
106 | * |
||
107 | * @return type mixed |
||
108 | */ |
||
109 | public function render404($request, $e) |
||
110 | { |
||
111 | $seg = $request->segments(); |
||
112 | if (in_array('api', $seg)) { |
||
113 | return response()->json(['status' => '404']); |
||
114 | } |
||
115 | if (config('app.debug') == true) { |
||
116 | if ($e->getStatusCode() == '404') { |
||
117 | return redirect()->route('error404', []); |
||
118 | } |
||
119 | |||
120 | return parent::render($request, $e); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
render() instead of render404() ). Are you sure this is correct? If so, you might want to change this to $this->render() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
121 | } |
||
122 | |||
123 | return redirect()->route('error404', []); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Function to render database connection failed. |
||
128 | * |
||
129 | * @param type $request |
||
130 | * @param type $e |
||
131 | * |
||
132 | * @return type mixed |
||
133 | */ |
||
134 | public function renderDB($request, $e) |
||
135 | { |
||
136 | $seg = $request->segments(); |
||
137 | if (in_array('api', $seg)) { |
||
138 | return response()->json(['status' => '404']); |
||
139 | } |
||
140 | if (config('app.debug') == true) { |
||
141 | return parent::render($request, $e); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
render() instead of renderDB() ). Are you sure this is correct? If so, you might want to change this to $this->render() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
142 | } |
||
143 | |||
144 | return redirect()->route('error404', []); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Common finction to render both types of codes. |
||
149 | * |
||
150 | * @param type $request |
||
151 | * @param type $e |
||
152 | * |
||
153 | * @return type mixed |
||
154 | */ |
||
155 | public function common($request, $e) |
||
156 | { |
||
157 | switch ($e) { |
||
158 | case $e instanceof HttpException: |
||
0 ignored issues
–
show
The class
App\Exceptions\HttpException does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
159 | return $this->render404($request, $e); |
||
0 ignored issues
–
show
The return type of
return $this->render404($request, $e); (Symfony\Component\HttpFoundation\Response ) is incompatible with the return type documented by App\Exceptions\Handler::common of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
160 | case $e instanceof NotFoundHttpException: |
||
161 | return $this->render404($request, $e); |
||
0 ignored issues
–
show
The return type of
return $this->render404($request, $e); (Symfony\Component\HttpFoundation\Response ) is incompatible with the return type documented by App\Exceptions\Handler::common of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
162 | case $e instanceof PDOException: |
||
0 ignored issues
–
show
The class
App\Exceptions\PDOException does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
163 | if (strpos('1045', $e->getMessage()) == true) { |
||
0 ignored issues
–
show
|
|||
164 | return $this->renderDB($request, $e); |
||
0 ignored issues
–
show
The return type of
return $this->renderDB($request, $e); (Symfony\Component\HttpFoundation\Response ) is incompatible with the return type documented by App\Exceptions\Handler::common of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
165 | } else { |
||
166 | return $this->render500($request, $e); |
||
0 ignored issues
–
show
The return type of
return $this->render500($request, $e); (Symfony\Component\HttpFoundation\Response ) is incompatible with the return type documented by App\Exceptions\Handler::common of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
167 | } |
||
168 | // case $e instanceof ErrorException: |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
169 | // if($e->getMessage() == 'Breadcrumb not found with name "" ') { |
||
170 | // return $this->render404($request, $e); |
||
171 | // } else { |
||
172 | // return parent::render($request, $e); |
||
173 | // } |
||
174 | default: |
||
175 | return $this->render500($request, $e); |
||
0 ignored issues
–
show
The return type of
return $this->render500($request, $e); (Symfony\Component\HttpFoundation\Response ) is incompatible with the return type documented by App\Exceptions\Handler::common of type App\Exceptions\type .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
176 | } |
||
177 | |||
178 | return parent::render($request, $e); |
||
0 ignored issues
–
show
return parent::render($request, $e); does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() It seems like you call parent on a different method (
render() instead of common() ). Are you sure this is correct? If so, you might want to change this to $this->render() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
179 | } |
||
180 | } |
||
181 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.