Dividing responsibilities - Part 2 Instead of creating a StockReport model from PurchaseOrderForStock objects, we could go directly to the source of the data, that is, the database where the application stores its purchase orders. If this is a relational database, there might be a table called purchaseorders, with columns for purchaseorderid, productid, orderedquantity, and wasreceived. If that's the case, then StockReportRepository wouldn't have to load any other object before it could build a StockReport object; it could make a single SQL query and use it to create the StockReport, as shown in Listing 11).
Dividing responsibilities - Part 1 We've looked at how objects can be used to retrieve information or perform tasks. The methods for retrieving information are called query methods, the ones that perform tasks are command methods. Service objects may combine both of these responsibilities. For instance, a repository (like the one in Listing 1) could perform the task of saving an entity to the database, and at the same time, it would also be capable of retrieving an entity from the database.
My favourite Git commit I like Git commit messages. Used well, I think they’re one of the most powerful tools available to document a codebase over its lifetime. I’d like to illustrate that by showing you my favourite ever Git commit.
How to write easily describable code When code is not describable using words, most people have to do some mental mapping to turn it in to words. This wastes mental energy, and you run the risk of getting the mapping wrong. Different people will map to different words, which leads to confusion when discussing the code.
The value of the void typehint in PHP When the void typehint was introduced in PHP 7.1. There was some debate about it. Some people wondered if it is beneficial to type nothing? I was one of them. Meanwhile, I changed my opinion on it. In this short post, I'd like to give you a small example where I think void shines.
REST Security Cheat Sheet REST (or REpresentational State Transfer) is an architectural style first described in Roy Fielding's Ph.D. dissertation on Architectural Styles and the Design of Network-based Software Architectures. It evolved as Fielding wrote the HTTP/1.1 and URI specs and has been proven to be well-suited for developing distributed hypermedia applications. While REST is more widely applicable, it is most commonly used within the context of communicating with services via HTTP.
Abstracting API calls with Symfony serializer As you can guess from reading the title this is not a getting started with article but it's about putting the Symfony components to work in order to solve day to day obstacles. But what did we solve?
How to use Data Providers in PHPUnit Data Providers are a handy feature of PHPUnit which allows you to run the same test with different inputs and expected results. This is useful when you are writing some text filtering, transformations, URL generation, price calculations, etc.
Clean Code: A Handbook of Agile Software Craftsmanship Clean Code is divided into three parts. The first describes the principles, patterns, and practices of writing clean code. The second part consists of several case studies of increasing complexity. Each case study is an exercise in cleaning up code—of transforming a code base that has some problems into one that is sound and efficient. The third part is the payoff: a single chapter containing a list of heuristics and “smells” gathered while creating the case studies. The result is a knowledge base that describes the way we think when we write, read, and clean code.
Service locator: an anti-pattern As a Laravel developer, I'm confronted daily with the service locator pattern. Every facade call and several helper functions are built upon it.
Let's take a look at a common facade call: Auth::user(). The Auth facade will reach into Laravel's service container, grab the registered component, and forward the static call to that component. In this case, it'll return the logged in user.
Vuestic Admin 2.0 - Free Vue.js Admin Template with 44 Custom UI Components Use Vuestic Admin 2.0 as a "building blocks" to save time on developing an admin panel for your app. In V2: - new, high-quality component design independent of Bootstrap - truly reusable components - more pages with tables and forms - we were on frontpage of PH yesterday - got platinum award on reddit
Intro Guide to Dockerfile Best Practices There are over one million Dockerfiles on GitHub today, but not all Dockerfiles are created equally. Efficiency is critical, and this blog series will cover five areas for Dockerfile best practices to help you write better Dockerfiles: incremental build time, image size, maintainability, security and repeatability. If you’re just beginning with Docker, this first blog post is for you! The next posts in the series will be more advanced.
How To Create Meaningful Names In Code As a developer, you spend a lot of your coding time making variables and thinking about proper names. Names are everywhere. You name files, classes, methods, and variables. As we spend so much time naming things it’s really important to do it well. In this article, I will show you some simple rules you can follow for creating good names. Naming things in your code is an art in itself!
10 must known rules for freelance projects — For Developers I have been in the IT industry for more than 10 years now and have done many out-sourced projects from all around the world. Projects exceed their deadlines, clients change their mind during the project, they won’t pay you on time and how they act to you is sometimes really, really annoying! Then you might get into trouble, arguments and worst case dropping lawsuits against each other, taking your time, mind and money. After years, finally, I have developed some disciplines and ways of doing freelance projects with the minimum effort.
My PHP Wishlist Back when I started using PHP properly in the early 5.0 days, it felt like the language was pretty basic. Other languages were making leaps and bounds every year, and as time went on, PHP seemed to have stagnated. The language wasn’t bad, but it wasn’t as good as it could’ve been.