Complex classes like LocalBusiness 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 LocalBusiness, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class LocalBusiness extends AbstractModel implements ModelInterface |
||
13 | { |
||
14 | |||
15 | static protected $DEFAULT_OPTIONS = array ( |
||
16 | 'base' => array( |
||
17 | 'default' => 'http://linkeddata.center/botk/resource/', |
||
18 | 'filter' => FILTER_SANITIZE_URL, |
||
19 | ), |
||
20 | 'uri' => array( |
||
21 | 'filter' => FILTER_SANITIZE_URL, |
||
22 | ), |
||
23 | 'lang' => array( |
||
24 | 'default' => 'it', |
||
25 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
26 | 'options' => array('regexp'=>'/^[a-z]{2}$/') |
||
27 | ), |
||
28 | 'id' => array( |
||
29 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
30 | 'options' => array('regexp'=>'/^[\w]+$/') |
||
31 | ), |
||
32 | 'taxID' => array( |
||
33 | 'filter' => FILTER_CALLBACK, |
||
34 | 'options' => '\BOTK\Filters::normalizeToken' |
||
35 | ), |
||
36 | 'vatID' => array( // italian rules |
||
37 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
38 | 'options' => array('regexp'=>'/^[0-9]{11}$/') |
||
39 | ), |
||
40 | 'legalName' => array( |
||
41 | 'filter' => FILTER_CALLBACK, |
||
42 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
43 | ), |
||
44 | 'alternateName' => array(), |
||
45 | 'addressCountry' => array( |
||
46 | 'default' => 'IT', |
||
47 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
48 | 'options' => array('regexp'=>'/^[A-Z]{2}$/') |
||
49 | ), |
||
50 | 'addressLocality' => array( |
||
51 | 'filter' => FILTER_CALLBACK, |
||
52 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
53 | ), |
||
54 | 'addressRegion' => array( |
||
55 | 'filter' => FILTER_CALLBACK, |
||
56 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
57 | ), |
||
58 | 'streetAddress' => array( |
||
59 | 'filter' => FILTER_CALLBACK, |
||
60 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
61 | ), |
||
62 | 'postalCode' => array( // italian rules |
||
63 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
64 | 'options' => array('regexp'=>'/^[0-9]{5}$/') |
||
65 | ), |
||
66 | 'page' => array( |
||
67 | 'filter' => FILTER_SANITIZE_URL |
||
68 | ), |
||
69 | 'telephone' => array( |
||
70 | 'filter' => FILTER_CALLBACK, |
||
71 | 'options' => '\BOTK\Filters::normalizeItTelephone' |
||
72 | ), |
||
73 | 'faxNumber' => array( |
||
74 | 'filter' => FILTER_CALLBACK, |
||
75 | 'options' => '\BOTK\Filters::normalizeItTelephone' |
||
76 | ), |
||
77 | 'email' => array( |
||
78 | 'filter' => FILTER_CALLBACK, |
||
79 | 'options' => '\BOTK\Filters::normalizeEmail' |
||
80 | ), |
||
81 | 'geoDescription' => array( |
||
82 | 'filter' => FILTER_CALLBACK, |
||
83 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
84 | ), |
||
85 | 'lat' => array( // http://www.regexlib.com/REDetails.aspx?regexp_id=2728 |
||
86 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
87 | 'options' => array('regexp'=>'/^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/') |
||
88 | ), |
||
89 | 'long' => array( // http://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates |
||
90 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
91 | 'options' => array('regexp'=>'/-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/') |
||
92 | ), |
||
93 | ); |
||
94 | |||
95 | |||
96 | public function asTurtle() |
||
182 | |||
183 | } |