Complex classes like CassandraTypesTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CassandraTypesTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | trait CassandraTypesTrait |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Check if object is instance of any cassandra object types |
||
12 | * |
||
13 | * @param $obj |
||
14 | * @return bool |
||
15 | */ |
||
16 | protected function isCassandraObject($obj) |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Returns comparable value from cassandra object type |
||
48 | * |
||
49 | * @param $obj |
||
50 | * @return mixed |
||
51 | */ |
||
52 | public function valueFromCassandraObject($obj) |
||
119 | |||
120 | } |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.