Conditions | 11 |
Paths | 18 |
Total Lines | 108 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
31 | public function main() |
||
32 | { |
||
33 | set_time_limit(0); |
||
34 | |||
35 | require_once('src/agavi.php'); |
||
36 | |||
37 | $this->olsonDir = realpath($this->olsonDir); |
||
38 | $this->outputDir = realpath($this->outputDir); |
||
39 | |||
40 | Config::set('olson.dir', $this->olsonDir); |
||
41 | |||
42 | Config::set('core.app_dir', getcwd() . '/etc/olson/agavi/app'); |
||
43 | Agavi::bootstrap(''); |
||
44 | |||
45 | $context = AgaviContext::getInstance(''); |
||
46 | |||
47 | if (!$this->olsonDir || !file_exists($this->olsonDir)) { |
||
48 | throw new BuildException('Olson data directory is not defined or does not exist.'); |
||
49 | } |
||
50 | |||
51 | if (!$this->outputDir || !file_exists($this->outputDir)) { |
||
52 | throw new BuildException('Timezone data output directory is not defined or does not exist.'); |
||
53 | } |
||
54 | |||
55 | $this->log("Building compiling olson files in {$this->olsonDir} to {$this->outputDir}", PROJECT_MSG_INFO); |
||
56 | |||
57 | $links = array(); |
||
58 | $zones = array(); |
||
59 | |||
60 | $di = new DirectoryIterator($this->olsonDir); |
||
61 | foreach ($di as $file) { |
||
62 | if ($file->isFile()) { |
||
63 | // the file doesn't contain an extension so we parse it |
||
64 | // and we don't want the factory time zone |
||
65 | if (strpos($file->getFilename(), '.') === false && $file->getFilename() != 'factory') { |
||
66 | $this->log(sprintf('compiling %s', $file->getPathname()), PROJECT_MSG_INFO); |
||
67 | $parser = new TimeZoneDataParser(); |
||
68 | $parser->initialize(AgaviContext::getInstance($context)); |
||
69 | $rules = $parser->parse($file->getPathname()); |
||
70 | $zones = $rules['zones'] + $zones; |
||
71 | $links = $rules['links'] + $links; |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | |||
76 | $baseCode = '<?php |
||
77 | |||
78 | /** |
||
79 | * %s |
||
80 | * %s |
||
81 | * |
||
82 | * @package agavi |
||
83 | * @subpackage translation |
||
84 | * |
||
85 | * @copyright Authors |
||
86 | * @copyright The Agavi Project |
||
87 | * |
||
88 | * @since 0.11.0 |
||
89 | * |
||
90 | * @version $Id' . '$ |
||
91 | */ |
||
92 | |||
93 | return %s; |
||
94 | |||
95 | ?>'; |
||
96 | |||
97 | $zoneList = array(); |
||
98 | |||
99 | foreach ($zones as $name => $zone) { |
||
100 | $fname = preg_replace('#([^a-z0-9_])#ie', "'_'.ord('\\1').'_'", $name) . '.php'; |
||
101 | $pathname = $this->outputDir . '/' . $fname; |
||
102 | $zone['name'] = $name; |
||
103 | |||
104 | $zoneList[$name] = array('type' => 'zone', 'filename' => $fname); |
||
105 | $this->log('Writing zone ' . $name . ' to: ' . $pathname); |
||
106 | file_put_contents( |
||
107 | $pathname, |
||
108 | sprintf( |
||
109 | $baseCode, |
||
110 | sprintf( |
||
111 | 'Data file for timezone "%s".', |
||
112 | $name |
||
113 | ), |
||
114 | sprintf( |
||
115 | 'Compiled from olson file "%s", version %s.', |
||
116 | $zone['source'], |
||
117 | $zone['version'] |
||
118 | ), |
||
119 | var_export($zone, true) |
||
120 | ) |
||
121 | ); |
||
122 | } |
||
123 | |||
124 | foreach ($links as $from => $to) { |
||
125 | $zoneList[$from] = array('type' => 'link', 'to' => $to); |
||
126 | } |
||
127 | |||
128 | $this->log('Writing zone listing to: ' . $this->outputDir . '/zonelist.php'); |
||
129 | file_put_contents( |
||
130 | $this->outputDir . '/zonelist.php', |
||
131 | sprintf( |
||
132 | $baseCode, |
||
133 | 'Zone list file.', |
||
134 | sprintf('Generated on %s.', gmdate('c')), |
||
135 | var_export($zoneList, true) |
||
136 | ) |
||
137 | ); |
||
138 | } |
||
139 | } |
||
140 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.