I was hired 3 weeks ago because of my gained experience in developing webapps. Team members and all of the colleagues are very kind and friendly. During this short period of time they let me implement a couple of features on my own.
So here is the thing: we are working with an unmaintained framework (zend 1). The code is kind of legacy due to "organic growth", there are static function calls all over the system. So I started to implement the features with a basic set of design patterns (DI, Facades), strict comparisons and null
avoidance like this:
// customer repository
public function getById(int $id): Customer
{
$customer = $this->findOneById($id);
if ($customer instanceof Customer === false) {
return new Customer; // or via factory call
}
return $customer;
}
Aside from the object creation, there were discussions about the instanceof
check, that a simple !$customer
would be enough in 99% of its cases. Furthermore they remove encapsulated code and merge together a factory and sending a mail into one single function. Maybe I've learned it all wrong, but IMHO this is a SOLID violation.
They hired me for my "expertise" but if I can't implement such architecture, how else shall I leave a better codebase than I've found?
instanceof
is generally not considered a good practice and frowned upon. I will say though, my experience with PHP is minimal. If I had to guess, then my thinking is your code will break for classes deriving fromCustomer
, likeElevatedCustomer
with yourinstanceof
check. There is a large variety of paradigms out there, your colleagues might deliver worse code than you do or maybe you don't realize where you are going wrong yourself - hard to tell from what I have read. Is it not possible to communicate with colleagues about paradigms?