for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the Clover to Html package.
*
* (c) Stéphane Demonchaux <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CloverToHtml;
class ConfigDAO
{
* @param string $templatePath
* @param string $key
* @throws \InvalidArgumentException
* @return array
public function findConfig($templatePath, $key = null)
if (is_file($this->getConfigPath($templatePath)) === false) {
throw new \InvalidArgumentException(
sprintf('Template "%s" with key "%s" not found', $templatePath, $key)
);
}
if ($key === null) {
return $config;
$config
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
function someFunction() { $x = 5; echo $x; }
The above code is perfectly fine. Now imagine that we re-order the statements:
function someFunction() { echo $x; $x = 5; }
In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.
$x
$config = $this->loadConfig($templatePath);
if (isset($config[$key])) {
return $config[$key];
* @return string
private function getConfigPath($templatePath)
return $templatePath.'/config.json';
private function loadConfig($templatePath)
return json_decode(file_get_contents($this->getConfigPath($templatePath)), true);
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.