Applied fixes from StyleCI

This commit is contained in:
onigoetz
2016-07-27 15:32:51 -04:00
committed by Stéphane Goetz
parent cfc8d30ba2
commit 2314516ce9
52 changed files with 477 additions and 424 deletions

View File

@ -46,7 +46,7 @@ class Builder
preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $m);
if (!isset($m[3])) {
throw new RuntimeException("Name not found");
throw new RuntimeException('Name not found');
}
return $m[3];
@ -137,17 +137,17 @@ class Builder
*/
public static function removeSortingInformations($filename)
{
preg_match("/^-?[0-9]*_?(.*)/", $filename, $matches);
preg_match('/^-?[0-9]*_?(.*)/', $filename, $matches);
// Remove the numeric part
// of the filename, only if
// there is something after
return empty($matches[1])? $matches[0] : $matches[1];
return empty($matches[1]) ? $matches[0] : $matches[1];
}
/**
* @param Directory $parent
* @param String $title
* @param string $title
* @return Directory
*/
public static function getOrCreateDir(Directory $parent, $title)
@ -185,7 +185,7 @@ class Builder
$title = static::getName($path);
$uri = DauxHelper::slug($title);
if ($parent->getConfig()['mode'] === Daux::STATIC_MODE) {
$uri .= ".html";
$uri .= '.html';
}
}
@ -193,8 +193,8 @@ class Builder
return $parent->getEntries()[$uri];
}
$page = $raw? new ComputedRaw($parent, $uri) : new Content($parent, $uri);
$page->setContent("-"); //set an almost empty content to avoid problems
$page = $raw ? new ComputedRaw($parent, $uri) : new Content($parent, $uri);
$page->setContent('-'); //set an almost empty content to avoid problems
$page->setName($path);
$page->setTitle($title);

View File

@ -111,11 +111,17 @@ class Content extends Entry
$lines = preg_split('/\n/', $sections[0]);
foreach ($lines as $line) {
$trimmed = trim($line);
if ($trimmed == '') continue; // skip empty lines
if ($trimmed[0] == '#') continue; // can be taken as comments
$re = "/^([-\\w]*)\\s*?:(.*)/";
if (!preg_match($re, $trimmed, $parts)) break; //Break as soon as we have a line that doesn't match
if ($trimmed == '') {
continue;
} // skip empty lines
if ($trimmed[0] == '#') {
continue;
} // can be taken as comments
$re = '/^([-\\w]*)\\s*?:(.*)/';
if (!preg_match($re, $trimmed, $parts)) {
break;
} //Break as soon as we have a line that doesn't match
$key = strtolower(trim($parts[1]));
$value = trim($parts[2]);

View File

@ -31,9 +31,9 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
continue;
}
if ($name[0] == "-") {
if ($name[0] == '-') {
if (is_numeric($name[1])) {
$exploded = explode("_", $name);
$exploded = explode('_', $name);
$buckets['down_numeric'][abs(substr($exploded[0], 1))][$key] = $entry;
continue;
}
@ -43,7 +43,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
}
if (is_numeric($name[0])) {
$exploded = explode("_", $name);
$exploded = explode('_', $name);
$buckets['numeric'][abs($exploded[0])][$key] = $entry;
continue;
}
@ -68,7 +68,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
private function sortBucket($bucket, $final)
{
uasort($bucket, function(Entry $a, Entry $b) {
uasort($bucket, function (Entry $a, Entry $b) {
return strcasecmp($a->getName(), $b->getName());
});
@ -103,7 +103,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
public function getConfig()
{
if (!$this->parent) {
throw new \RuntimeException("Could not retrieve configuration. Are you sure that your tree has a Root ?");
throw new \RuntimeException('Could not retrieve configuration. Are you sure that your tree has a Root ?');
}
return $this->parent->getConfig();
@ -139,7 +139,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
*/
public function seekFirstPage()
{
if ($this instanceof Directory) {
if ($this instanceof self) {
$index_key = $this->getConfig()['index_key'];
if (isset($this->children[$index_key])) {
return $this->children[$index_key];
@ -148,13 +148,14 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
if ($node instanceof Content) {
return $node;
}
if ($node instanceof Directory
if ($node instanceof self
&& strpos($node->getUri(), '.') !== 0
&& $childNode = $node->seekFirstPage() ) {
&& $childNode = $node->seekFirstPage()) {
return $childNode;
}
}
}
return null;
}
@ -176,14 +177,16 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
}
$this->setFirstPage($node);
return $node;
}
}
// If we can't find one we check in the sub-directories
foreach ($this->getEntries() as $node) {
if ($node instanceof Directory && $page = $node->getFirstPage()) {
if ($node instanceof self && $page = $node->getFirstPage()) {
$this->setFirstPage($page);
return $page;
}
}
@ -210,7 +213,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
foreach ($this->getEntries() as $node) {
if ($node instanceof Content) {
return true;
} elseif ($node instanceof Directory) {
} elseif ($node instanceof self) {
if ($node->hasContent()) {
return true;
}
@ -237,7 +240,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
/**
* Whether a offset exists
* @param mixed $offset An offset to check for.
* @return boolean true on success or false on failure.
* @return bool true on success or false on failure.
*/
public function offsetExists($offset)
{
@ -263,7 +266,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
public function offsetSet($offset, $value)
{
if (!$value instanceof Entry) {
throw new RuntimeException("The value is not of type Entry");
throw new RuntimeException('The value is not of type Entry');
}
$this->addChild($value);

View File

@ -159,6 +159,7 @@ abstract class Entry
}
$url .= $this->getUri();
return $url;
}
@ -170,7 +171,7 @@ abstract class Entry
'name' => $this->getName(),
'uri' => $this->getUri(),
'url' => $this->getUrl(),
'path' => $this->path
'path' => $this->path,
];
}
}