Offcanvas

Find errors without running your code!

Find errors without running your code!
intcore
By: Mark Rady

 

Hassle of finding code errors!

Finding errors in your code without interrupting your code could be something normal for a lot of people, but imagine that you have an old code base or a legacy code.

You will have thousands of files, most probably will have a lot of logical errors, for example: functions return multiple types of data…etc.

This scenario couldn’t happen if you use compiled language, a strongly typed language.

Languages!

As a PHP developer using a dynamic language one doesn't have to specify methods to return types or variables, at some times you could make a function return with user object in condition and in another condition could return string for example “user not found.”.

Could be given for you but as a code standard and quality you could get confused when this method is called because it should be return [ex User instance] and when you try to call a method from this instance you could get error Cannot call method on string.

Maybe you don’t consider it a problem or you are handling it with check return type of functions, but if you are working on large scale projects with many team members you will get something like lag in development or have a good understanding of what this function returns exactly.

At Intcore, we have lots of quality standards of coding and to make code review easier, to make sure the development process is going smoothly and avoid random errors or sudden errors could happen in some scenarios and others not.

For example you could get this error before defining a variable inside if condition and return this variable outside if condition, and as a good scenario you think in your subconscious it will pass!

I will use PHPStan package from github to test my code for fresh project based on laravel

Let’s go!

Okay, let's think about that this code has actually worked, if you read where is the error exactly, you will find this error in exception handler in laravel.

Let’s explore!

Code looks perfect but there are 2 small issues; 

  1. In function’s comment, it is defined that function should return instance of \Illuminate\Http\Response but the function is returned instance of App\User

  2. User variable is defined inside if condition and we tried to return variable after the if condition.

These could seem like small issues but on a big scale project and legacy code base, thousands of issues were found, we have a big issue with random issues appear on production and fields queues, after fixing these issues we almost passed 80% of issues. 

By the way, there is a lot of packages providing the same functionality of Phpsan and there are multiple levels of testing your code you can select the level of code quality you need to check.

Stay tuned for more of our articles on our blog

People liked
4 Steps to Improve your Content Marketing Strategy
4 Steps to Improve y...

While a lot of people might argue that content marketing is very time consuming and hectic, the fact that it works can’t be denied. The reality is that content marketing has become a new way of reaching out to people. Instead of cold calling or distributing flyers, what marketers can do is that they can market their business through their content.

7 weird websites you knew nothing about
7 weird websites you...

you open those websites and start questioning yourself "what were those developers actually doing" ?!

How to Build a Relationship with Your Followers
How to Build a Relat...

When it comes to taking your business to another level in this day and age, your followers are pretty much invaluable, to say the least. Your followers are so important for your company that they might as well be referred to as the lifeblood of your business. So it’s crucial to build a steady relationship with them to retain them and make them loyal to you. Because loyal customers, one way or the other, bring more business to your firm.

How to measure your work on social media
How to measure your...

Can you measure the success of your work? As a business owner can you evaluate your social media specialist? There are so many of the social media specialists who don't know how to measure their work.On that base, they lose two things. First, they don't know where they stand, when they need to improve and if what they do have good results or not. Second, they lose their clients because they don't know how to display their work with results so the client has one solution only which is canceling the contract and searching for another social media specialist who gives a full detailed report at the end of every month.

Offcanvas Title
Your content here.