1313use Propel \Common \Config \Exception \InvalidArgumentException ;
1414use Propel \Common \Config \Exception \InvalidConfigurationException ;
1515use Propel \Common \Config \Loader \DelegatingLoader ;
16- use Symfony \Component \Finder \Finder ;
1716use Symfony \Component \Config \Definition \Processor ;
17+ use Symfony \Component \Finder \Finder ;
1818
1919/**
2020 * Class ConfigurationManager
2525 */
2626class ConfigurationManager
2727{
28- const CONFIG_FILE_NAME = 'propel ' ;
28+ public const CONFIG_FILE_NAME = 'propel ' ;
2929
3030 /**
3131 * Array of configuration values
@@ -37,8 +37,8 @@ class ConfigurationManager
3737 /**
3838 * Load and validate configuration values from a file.
3939 *
40- * @param string|null $filename Configuration file name or directory in which resides the configuration file.
41- * @param array $extraConf Array of configuration properties, to be merged with those loaded from file.
40+ * @param string|null $filename Configuration file name or directory in which resides the configuration file.
41+ * @param array $extraConf Array of configuration properties, to be merged with those loaded from file.
4242 * It's useful when passing configuration parameters from command line.
4343 */
4444 public function __construct ($ filename = null , $ extraConf = [])
@@ -61,7 +61,8 @@ public function get()
6161 * Return a specific section of the configuration array.
6262 * It ca be useful to get, in example, only 'generator' values.
6363 *
64- * @param string $section the section to be returned
64+ * @param string $section the section to be returned
65+ *
6566 * @return array|null
6667 */
6768 public function getSection ($ section )
@@ -81,9 +82,11 @@ public function getSection($section)
8182 * is expressed by:
8283 * <code>'database.adapter.mysql.tableType</code>
8384 *
84- * @param string $name The name of property, expressed as a dot separated level hierarchy
85+ * @param string $name The name of property, expressed as a dot separated level hierarchy
86+ *
8587 * @throws \Propel\Common\Config\Exception\InvalidArgumentException
86- * @return mixed The configuration property
88+ *
89+ * @return mixed The configuration property
8790 */
8891 public function getConfigProperty ($ name )
8992 {
@@ -107,12 +110,13 @@ public function getConfigProperty($name)
107110 * Return an array of parameters relative to configured connections, for `runtime` or `generator` section.
108111 * It's useful for \Propel\Generator\Command\ConfigConvertCommand class
109112 *
110- * @param string $section `runtime` or `generator` section
113+ * @param string $section `runtime` or `generator` section
114+ *
111115 * @return array|null
112116 */
113117 public function getConnectionParametersArray ($ section = 'runtime ' )
114118 {
115- if (!in_array ($ section , ['runtime ' , 'generator ' ])) {
119+ if (!in_array ($ section , ['runtime ' , 'generator ' ], true )) {
116120 return null ;
117121 }
118122
@@ -132,8 +136,9 @@ public function getConnectionParametersArray($section = 'runtime')
132136 * Only one configuration file is supposed to be found.
133137 * This method also looks for a '.dist' configuration file and loads it.
134138 *
135- * @param string|null $fileName Configuration file name or directory in which resides the configuration file.
139+ * @param string|null $fileName Configuration file name or directory in which resides the configuration file.
136140 * @param array|null $extraConf Array of configuration properties, to be merged with those loaded from file.
141+ *
137142 * @return void
138143 */
139144 protected function load ($ fileName , $ extraConf )
@@ -144,19 +149,19 @@ protected function load($fileName, $extraConf)
144149 $ fileName = self ::CONFIG_FILE_NAME ;
145150 }
146151
147- if (null === $ extraConf ) {
152+ if ($ extraConf === null ) {
148153 $ extraConf = [];
149154 }
150155
151- if (static :: CONFIG_FILE_NAME === $ fileName ) {
156+ if ($ fileName === static :: CONFIG_FILE_NAME ) {
152157 $ files = $ this ->getFiles ($ dirs , $ fileName );
153158 $ distFiles = $ this ->getFiles ($ dirs , $ fileName , true );
154159
155160 $ numFiles = count ($ files );
156161 $ numDistFiles = count ($ distFiles );
157162
158163 //allow to load only .dist file
159- if (0 === $ numFiles && 1 === $ numDistFiles ) {
164+ if ($ numFiles === 0 && $ numDistFiles === 1 ) {
160165 $ files = $ distFiles ;
161166 $ numFiles = 1 ;
162167 }
@@ -171,21 +176,22 @@ protected function load($fileName, $extraConf)
171176 $ fileName = $ file ->getPathName ();
172177 }
173178
174- $ this ->config = array_replace_recursive ($ this ->loadFile ($ fileName. '.dist ' ), $ this ->loadFile ($ fileName ), $ extraConf );
179+ $ this ->config = array_replace_recursive ($ this ->loadFile ($ fileName . '.dist ' ), $ this ->loadFile ($ fileName ), $ extraConf );
175180 }
176181
177182 /**
178183 * Validate the configuration array via Propel\Common\Config\PropelConfiguration class
179184 * and add default values.
180185 *
181- * @param array $extraConf Extra configuration to merge before processing. It's useful when a child class overwrite
186+ * @param array|null $extraConf Extra configuration to merge before processing. It's useful when a child class overwrite
182187 * the constructor to pass a built-in array of configuration, without load it from file. I.e.
183188 * Propel\Generator\Config\QuickGeneratorConfig class.
189+ *
184190 * @return void
185191 */
186192 protected function process ($ extraConf = null )
187193 {
188- if (null === $ extraConf && count ($ this ->config ) <= 0 ) {
194+ if ($ extraConf === null && count ($ this ->config ) <= 0 ) {
189195 return ;
190196 }
191197
@@ -205,9 +211,11 @@ protected function process($extraConf = null)
205211 /**
206212 * Return an array of configuration files in the $dirs directories
207213 *
208- * @param array $dirs The directories where to find the configuration files
214+ * @param array $dirs The directories where to find the configuration files
209215 * @param string $fileName The name of the file
210- * @param bool $dist If search .dist files
216+ * @param bool $dist If search .dist files
217+ *
218+ * @throws \Propel\Common\Config\Exception\InvalidArgumentException
211219 *
212220 * @return array
213221 */
@@ -216,7 +224,7 @@ private function getFiles($dirs, $fileName, $dist = false)
216224 $ finder = new Finder ();
217225 $ fileName .= '.{php,inc,ini,properties,yaml,yml,xml,json} ' ;
218226
219- if (true === $ dist ) {
227+ if ($ dist === true ) {
220228 $ fileName .= '.dist ' ;
221229 }
222230
@@ -236,7 +244,6 @@ private function getFiles($dirs, $fileName, $dist = false)
236244 * @param string $fileName The configuration file
237245 *
238246 * @return array|mixed
239- * @throws \Symfony\Component\Config\Exception\LoaderLoadException|\Symfony\Component\Config\Exception\FileLoaderLoadException
240247 */
241248 private function loadFile ($ fileName )
242249 {
@@ -252,7 +259,8 @@ private function loadFile($fileName)
252259 /**
253260 * Return the directories where to find the configuration file.
254261 *
255- * @param string|null $fileName
262+ * @param string|null $fileName
263+ *
256264 * @return array
257265 */
258266 private function getDirs ($ fileName )
@@ -268,11 +276,11 @@ private function getDirs($fileName)
268276 }
269277
270278 $ dirs [] = $ currentDir ;
271- if (is_dir ($ currentDir. '/conf ' )) {
272- $ dirs [] = $ currentDir. '/conf ' ;
279+ if (is_dir ($ currentDir . '/conf ' )) {
280+ $ dirs [] = $ currentDir . '/conf ' ;
273281 }
274- if (is_dir ($ currentDir. '/config ' )) {
275- $ dirs [] = $ currentDir. '/config ' ;
282+ if (is_dir ($ currentDir . '/config ' )) {
283+ $ dirs [] = $ currentDir . '/config ' ;
276284 }
277285
278286 return $ dirs ;
@@ -296,6 +304,8 @@ private function cleanupSlaveConnections()
296304 * If not defined, set `runtime` and `generator` connections, based on `database.connections` property.
297305 * Check if runtime and generator connections are correctly defined.
298306 *
307+ * @throws \Propel\Common\Config\Exception\InvalidConfigurationException
308+ *
299309 * @return void
300310 */
301311 private function cleanupConnections ()
@@ -314,14 +324,14 @@ private function cleanupConnections()
314324
315325 foreach ($ this ->config [$ section ]['connections ' ] as $ connection ) {
316326 if (!array_key_exists ($ connection , $ this ->config ['database ' ]['connections ' ])) {
317- throw new InvalidConfigurationException ("` $ connection` isn't a valid configured connection (Section: propel. $ section.connections). " .
318- " Please, check your configured connections in `propel.database.connections` section of your configuration file. " );
327+ throw new InvalidConfigurationException ("` $ connection` isn't a valid configured connection (Section: propel. $ section.connections). " .
328+ ' Please, check your configured connections in `propel.database.connections` section of your configuration file. ' );
319329 }
320330 }
321331
322332 if (!array_key_exists ($ defaultConnection = $ this ->config [$ section ]['defaultConnection ' ], $ this ->config ['database ' ]['connections ' ])) {
323- throw new InvalidConfigurationException ("` $ defaultConnection` isn't a valid configured connection (Section: propel. $ section.defaultConnection). " .
324- " Please, check your configured connections in `propel.database.connections` section of your configuration file. " );
333+ throw new InvalidConfigurationException ("` $ defaultConnection` isn't a valid configured connection (Section: propel. $ section.defaultConnection). " .
334+ ' Please, check your configured connections in `propel.database.connections` section of your configuration file. ' );
325335 }
326336 }
327337 }
0 commit comments