Clean Code
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability. General rules Follow standard conventions. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible. Boy scout rule. Leave the campground cleaner than you found it. Always find root cause. Always look for the root cause of a problem. Design rules Keep configurable data at high levels. Prefer polymorphism to if/else or switch/case. Separate multi-threading code. Prevent over-configurability. …
What is dependency Injection?
The ability to provide a component with its dependence either via construction injection, method calls or the setting of properties. …
What is a namespace, and how would you use it?
Namespaces are generally used to “group” sections of code with other related pieces of code, and can assist with code reusability. Namespaces prevent collision between different packages that have classes of the same name …
What is type declaration (also known as type hinting)
Good responses = A way to require parameters of functions to be of a certain type when called. (Bonus points if strict typing is mentioned) Type declaration ensures that parameters are always of the expected type. This reduces validation requirements for the developer. …
What are the 3 scopes that a class property or method can be declare as? What is the difference?
Responses = Private – the property/method can only be used by the class that defined it Protected – the property/method can only be used by the class that defined it and any sub-classes Public – the property/method can be called by any class …
What is class abstraction?
Good response = An abstract class is a class that cannot be instantiated and contains abstract methods that are used to define method signature rather than the implementation of the method. Any inheritance of the abstract class must implement any defined abstract methods, and cannot change the original signature. It is generally used to allow for similar usage across different implementation of code. …
Explain what what is a Trait?
Good response = A Trait is a reusable class that can provide fine-grained (small) sections functionality …
PHP Coding Standards
Fortunately for PHP developers, there is the PHP Standards Recommendation (PSR), comprised of the following five standards: PSR-0: Autoloading Standard PSR-1: Basic Coding Standard PSR-2: Coding Style Guide PSR-3: Logger Interface PSR-4: Autoloader PSR was originally created based on inputs from maintainers of the most recognized platforms on the market. Zend, Drupal, Symfony, Joomla and others contributed to these standards, and are now following them. Even PEAR, which attempted to be a standard for years before that, participates in PSR now. In some sense, it almost doesn’t matter what your coding standard is, as long as you agree on a …