در حال بارگذاری ...

Review GitHub Actions Checks0:00

Many open-source repositories use GitHub Actions to ensure that the code you are trying to submit actually works and follows the standards set by the repository. In the case of Laravel Prompt, we have GitHub Actions that will run our tests. You can see that they're all passing because of this tick next to each one, so that's good news. But we currently have a failing check on static analysis. There's no need to panic when anything like this happens. It's completely normal and it usually doesn't take long to fix. Let's check the details. The details tell us that when running vendor/bin/phpstan, which obviously is what this particular package

Reproduce PHPStan Errors0:39

Let's check the details. The details tell us that when running vendor/bin/phpstan, which obviously is what this particular package is using for type checking, there were 7 errors. This is not a lesson on phpstan. We have a series explaining the basics of phpstan, so if you're unfamiliar, go ahead and watch that. But I will at least walk you through how I'm going to fix this problem. From the terminal, let's replicate what we see in GitHub Actions by running vendor/bin/phpstan. And yeah, here are those 7 errors that we saw in GitHub. So we'll start with the step builder and it tells us which lines we should look at,

Fix StepBuilder Types1:12

And yeah, here are those 7 errors that we saw in GitHub. So we'll start with the step builder and it tells us which lines we should look at, starting on line 37. Jump into step builder, line 37, and right away I can see the problem is it returns an array but that's not enough information for the current level of PHPStan. So let's say at return array, and seeing as this is returning a mixed type, I'll just return mixed there. Let's move on to the next error, line 22, add has no return type specified. So here we've forgotten to say that it returns self. No problems, a nice easy fix.

So here we've forgotten to say that it returns self. No problems, a nice easy fix. 17, responses has no value type specified in iterable type array. Let's come up to responses here. We can make this more clear by setting var array, and the response again can be mixed, so we'll set it to mixed. For steps, again, at var array, and this can have a key of int, seen as steps will always be numeric and indexed. And then the second item, of course, will be Laravel, prompt, and then we're looking for the Step class that we created.

Fix Step Closure Issues2:19

And then the second item, of course, will be Laravel, prompt, and then we're looking for the Step class that we created. Let's rerun vendor/bin/phpstan to see if that's fixed some errors. Indeed it has, we have three left, all inside the Step class itself. Let's jump into there. So first of all, line 39, line 39 says that we try to invoke the closure but it might not be a callable. So I'm pretty sure this is because PHPStan isn't able to determine that this is actually preventing this from ever being a problem. There are different ways we could handle it, I think for now I'm just going to take this.

preventing this from ever being a problem. There are different ways we could handle it, I think for now I'm just going to take this code and I'm going to paste it into the if statement directly, and I'll use an instance of check. If this previous revert is an instance of closure, then we can execute it. I'm pretty sure that would fix the problem. And whilst we're at it, why don't we use the same check in the if statement above, which essentially is the same thing, just reverted for clarity. Okay, line 36, revert has parameter responses with no value type. That's not a problem.

Okay, line 36, revert has parameter responses with no value type. That's not a problem. So this is here. We can say @param, we're looking for an array. It's going to have mixed responses because it could be anything that has come back from the step closures. And of course, it's for the parameter responses, as we can see here. I'll copy this because there's another method up here, run, which requires the same thing. And now let's rerun phpstan, everything's passing. Let's also run vendor/bin/phpunit to make sure all the tests pass.

Rerun Tests and Push3:49

And now let's rerun phpstan, everything's passing. Let's also run vendor/bin/pest to make sure all the tests pass. Yep, looks like we're good to go. So let's run work in progress. And then we could git push to put this back up onto GitHub, and we can check GitHub actions from the front end. And after a few minutes, you can see that GitHub actions has successfully passed all four checks, meaning phpstan is happy, the tests are happy, and that's one less thing blocking us from being able to merge this pull request.

blocking us from being able to merge this pull request.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟