PHP Reddit – Telegram
PHP Reddit
34 subscribers
286 photos
36 videos
24.7K links
Channel to sync with /r/PHP /r/Laravel /r/Symfony. Powered by awesome @r_channels and @reddit2telegram
Download Telegram
well:

1. They encapsulate any database access and return the required object and
2. They become a repository for complex queries (huh, maybe that's why they're called that?)

You can also do really cool stuff with them, like wrap them in a decorator for caching, swap persistence strategies at runtime (maybe you have a Redis front, but fallback to the rdbms if redis is down). I've seen criticisms around Repositories which again make me feel like those authors or creators have never worked on a large, complex, evolving application before. They just don't seem like they've seen the front battlelines, they've never been in the trenches, as many seniors have. Ignorance is bliss, as the saying goes (that's not a hateful comment, btw - I'm genuinely jealous).

# Tests alongside code

In almost every PHP project I've seen, and definitely all Laravel projects, all tests live in the tests/ directory, and often mimic the directory structure of your application, where you can find (hopefully) a 1:1 mapping of test file to class file. With 500k lines of code in an application, and 10000 unique test cases, and 40000 assertions, this becomes a real mess. What we do, is the following: our tests live right alongside the class they're testing. And, we go one, manic step further:

* User.php
* User.test.php

The astute amongst you have already noticed the break away from conventions, here: our test file extension. User.test.php is still UserTest as a class, but we call it .test.php so that the file is literally right next to the class it's testing. Else you see silly things like this:

* User.php
* UserRepository.php
* UserService.php
* UserTest.php
* UserRepositoryTest.php

This might seem a small thing, but on large applications it's a real pain, particularly if (in some of our cases), the folder has 30+ files (including tests). It just becomes harder to manually find the test you're looking for (of course, you can always use your IDE shortcut, which is what we mostly do, but sometimes you just gotta eyeball things - **O.O**).

This is supported by our phpunit.xml configuration, as well as some custom bindings/setup to make it all work.

Is it the right approach? Not necessarily, and maybe not for your project. But ever since we started doing this, I do this in all of my projects now. This is true of our feature/acceptance tests as well, where they live alongside the controller or action they're designed to test. This has the added benefit of seeing where there are obvious gaps in our test suite, without needing to do any code coverage analysis, which by the way, can take forever and a day on a large code base!

I'll wrap this up because I have a bunch more I could write and am thinking about doing so on my own YouTube channel (to come soon), but I could honestly write full essays on each of these points, and will likely talk about them in even greater detail in long-form video.

So let me close by reiterating what I've said before. I am not against all these things or their nature. They have their uses, and they work great at various application sizes, it depends on the use-case. What I am against, is evangelical/ideological views that make bold claims that X is bad and should never be used or Y is the best, always use it. I am against the claim that you should "just follow laravel/php/node/whatever conventions". These are arguments that are not rooted in reality, and lack critical thinking, they lack nuance. As a senior software engineer, you need to be thinking critically about every... single... layer. You have to be a slave to nuance, details, or you'll miss things, and you'll make mistakes, mistakes that cost you or your company a fortune.

It is important as developers that we continue to learn and grow, but most importantly, ***be pragmatic***. The suggestions I've made here are not to say "you should replace all conventions or you're a bad developer". Quite the contrary - I've offered alternatives and reasons for doing so, *when it makes sense*, that you do not ***need*** to follow conventions just because someone told you
to.

Every engineering concept has its use-case, its pros and cons, and has gotchas that you need to be mindful of. But as you master your craft, you begin to understand the intent behind these approaches, how best to utilise them so that you can reap the greatest value they provide. Don't do something because someone told you to, do it because you find it interesting and want to continue to grow, and in doing so, become the Engineer you were always meant to be.

If you made it this far, thank you - I value your time and hope I was able to communicate the thoughts that have been running around my head for the last few years. Let me know what you think, and if you disagree, even moreso. I like being challenged and being proven wrong, because it means I learnt something new, and that makes me a better Engineer.

Cheers!

https://redd.it/1p04d6e
@r_php
Open-source eMarket Online Store v1.0 RC-3.5

Greetings, dear colleagues.

This time, I've decided to outline the latest innovations in the eMarket project - https://github.com/musicman3/eMarket.

I'd really appreciate any helpful advice and criticism, as it gives me a better understanding of where to go next. Following previous publications, conclusions have been drawn, and a great deal of work has been done to implement many ideas and approaches.

Currently, the following key libraries have been separated into separate repositories and significantly improved:

Cruder (DB Query Builder) - https://github.com/musicman3/Cruder

R2-D2 (Autorouter) - https://github.com/musicman3/r2-d2

These libraries are now available for study and development, should anyone need them. They form the foundation of eMarket.

Furthermore, jsonRPC has been separately implemented for use as microservices and other purposes. In the future, this will allow for much more efficient handling of external requests. This has proven to be very convenient in practice and will be further developed. The jsonRPC library is also written within the project and is part of it. There was no point in making it a separate library yet, as the code is quite simple.

An automatic updater has already been implemented for the project, which took quite a while. Now you can update directly from the admin panel.

It is also possible to use the platform as a hybrid CMS and online store. This is often necessary for a website that has a denoscriptive section and simultaneously sells products.

Small additions include adding a custom logo and editing language variables from the admin panel.

Best regards.

https://redd.it/1p08xo1
@r_php
PHP Version Update Breaking Stuff

Whenever I bump PHP to the latest version, something on my site breaks, usually some dusty old plugin. I want the speed boost but NOT the stress. How do you guys handle PHP updates without your site falling apart?

https://redd.it/1p0zi91
@r_php
Who's hiring/looking

This is a bi-monthly thread aimed to connect PHP companies and developers who are hiring or looking for a job.

Rules

No recruiters
Don't share any personal info like email addresses or phone numbers in this thread. Contact each other via DM to get in touch
If you're hiring: don't just link to an external website, take the time to describe what you're looking for in the thread.
If you're looking: feel free to share your portfolio, GitHub, … as well. Keep into account the personal information rule, so don't just share your CV and be done with it.

https://redd.it/1p12myc
@r_php