پی اچ پی

استاندارد کردن کد های بزرگ

Whip Monstrous Code Into Shape

You did your best, but somehow that User object, over time, morphed into a monstrous God object. And your controllers started out nice and clean, but now... not so much.

We've all been there. In this series, we'll review a number of ideas for whipping convoluted code into shape.

سطح حرفه ای 20 جلسه آموزشی 03:40:00 ساعت
01
قسمت 1

Consider Form Objects

A form object manages a single form in your application. It handles validation, potentially authorization, and finally - if you wish - persistence. In this lesson, we'll write an implementation from scratch, and then switch over to reviewing Laravel'...

02
قسمت 2

Consider Use Cases

A use case is nothing more than a description of how a user should interact with a particular part of your system. Traditionally, this description may be written on something as simple as an index card. However, what if we applied this approach to th...

03
قسمت 3

Consider Domain Events

If it makes sense for your application, you might consider leveraging domain events and listeners to construct a complex set of functionality.

04
قسمت 4

God Object Cleanup #1: Pass-Through

Any developer who has worked on the same project for a year or more will be well aware of the fact that, if you're not careful, your User class can quickly turn into a monstrous God object. In the next few videos, one tip at a time, we'll review tech...

05
قسمت 5

God Object Cleanup #2: Traits and Socks

Let's review the next option you have, when cleaning up big, bad God objects: extracting traits. While some developers have knee-jerk reactions to the concept of a trait that will never be used elsewhere, I find it to be a clean and convenient soluti...

06
قسمت 6

God Object Cleanup #3: Value Objects

Extracting value objects, when appropriate, can be a useful technique for cleaning up messy classes. Use a simple metric: if you find multiple pieces of behavior that surround a single primitive or value, consider a value object. Please note that dev...

07
قسمت 7

Consider Policies

If you find that your controllers are performing too much authorization logic, you might consider policy objects. This allows you to assign a name to important (possibly complex) authorization logic that can reused anywhere. Or, in other words, if yo...

08
قسمت 8

Consider Splitting Tasks into Steps

What do you do in the situations where a particular task consists of a dozen different unique steps? Well we've already reviewed a number of options in this series, including use-cases and events; however, another perfectly acceptable route is to ext...

09
قسمت 9

Consider Strategizing

Tutorials often illustrate the simplest possible path through your codebase to demonstrate a particular concept. But the truth is that, in real life, things can quickly become quite a bit more complicated. For example, imagine that your website allow...

10
قسمت 10

Consider Normalizing

You'll frequently find yourself in the position of needing to normalize a particular value. Sure, the value might be in the proper format from the start; but it could also be in the form of a function that you need to trigger. Or maybe, based upon va...

11
قسمت 11

Consider View Models

When you find yourself repeating the same view logic over and over, it might be time to extract that code into a reusable method. At first, developers typically reach for the model. However, you may quickly decide that you'd prefer a more dedicated c...

12
قسمت 12

Too Many Method Parameters is a Sign

As a general guideline, when you find yourself wanting to create a method with four or more parameters, that might be an indication that there's a missing class. You may want to refactor. As always, rules are meant to be broken, but, nonetheless, tra...

13
قسمت 13

Consider Decorating

The next option you have when cleaning up monstrous code is opting for decorators. This allows you to stack on behavior to an existing class dynamically. I'll show you how; it's easy!

14
قسمت 14

Consider Fluent Interfaces

Fluent interfaces often get a bad rap, but the truth is that there are countless scenarios where you may consider leveraging them. In this episode, we'll review the basic definition and makeup for a fluent API, and will then move on discussing a hand...

15
قسمت 15

Hands On Refactoring

Let's put some of the skills we've learned in this series to the test. We'll take an existing real-life class, and refactor it using the techniques we reviewed in episode eight of this series. View a sampling of the source from this lesson on GitH...

16
قسمت 16

Staying True to the Seven Resourceful Methods

In this monstrous code episode, we'll review one technique to help keep your controllers in check. Have you ever created a resourceful controller, but found yourself, over time, adding more and more actions to it? It starts to get pretty bloated, rig...

17
قسمت 17

Consider Query Objects

Most tutorials demonstrate the simplest possible Eloquent queries. You know, the one where you do Post::all() and move on. But, in reality, you're often writing significantly more complex queries. So what do we do, when they get too large and gross t...

18
قسمت 18

Consider Refactoring Your Views

So you've begun to wrangle your monstrous User God object into place? Great - but now what about your views? Developers sometimes have a tendency to ignore the structure and cleanliness of their templates. Try not to do this. Give the same respect to...

19
قسمت 19

Consider a Guest User Class

Have you ever found yourself in the situation where you're constantly checking, within your views, to see if a user is signed in before proceeding? "If the user is signed in, and if they are subscribed, then...." It gets annoying, doesn't it? Hmm - w...

20
قسمت 20

Consider Wrapping it Up

Imagine that you perform an API request to fetch a bit of JSON. That response will become an array of objects, once decoded. Too often, though, I see developers littering their views or creating helper functions, all to add a bit of behavior or forma...

دوره در حال اجرا

این دوره هنوز به پایان نرسیده است و در آینده درس های دیگری به آن افزوده خواهد شد.