Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Apply PSR-2 coding conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Aug 27, 2017
1 parent a10cdd3 commit fe8b9a3
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 86 deletions.
10 changes: 5 additions & 5 deletions code/DocumentationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class DocumentationHelper
{
/**
* String helper for cleaning a file name to a readable version.
* String helper for cleaning a file name to a readable version.
*
* @param string $name to convert
*
Expand Down Expand Up @@ -95,9 +95,9 @@ public static function get_extension($name)

/**
* Helper function to normalize paths to unix style directory separators
*
*
* @param string
*
*
* @return string
*/
public static function normalizePath($path)
Expand All @@ -111,9 +111,9 @@ public static function normalizePath($path)

/**
* Helper function to make normalized paths relative
*
*
* @param string
*
*
* @return string
*/
public static function relativePath($path)
Expand Down
26 changes: 19 additions & 7 deletions code/DocumentationManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public function __construct($forceRegen = false)
$this->registeredEntities = new ArrayList();

$this->cache = SS_Cache::factory(
'DocumentationManifest', 'Core', array(
'DocumentationManifest',
'Core',
array(
'automatic_serialization' => true,
'lifetime' => null
)
Expand Down Expand Up @@ -159,7 +161,8 @@ public function setupEntities()
* @var DocumentationEntity $entity
*/
$entity = Injector::inst()->create(
'DocumentationEntity', $key
'DocumentationEntity',
$key
);

$entity->setPath(DocumentationHelper::normalizePath(Controller::join_links($path, $lang, '/')));
Expand Down Expand Up @@ -242,7 +245,9 @@ public function populateEntitiesFromInstall()
}

Config::inst()->update(
'DocumentationManifest', 'register_entities', $entities
'DocumentationManifest',
'register_entities',
$entities
);

$this->automaticallyPopulated = true;
Expand Down Expand Up @@ -371,7 +376,8 @@ public function regenerate($cache = true)

foreach ($grouped as $entity) {
uasort(
$entity, function ($a, $b) {
$entity,
function ($a, $b) {
// ensure parent directories are first
$a['filepath'] = str_replace('index.md', '', $a['filepath']);
$b['filepath'] = str_replace('index.md', '', $b['filepath']);
Expand Down Expand Up @@ -417,7 +423,8 @@ protected function stripLinkBase($link)
Config::inst()->get('DocumentationViewer', 'link_base'),
'',
$link
), '/'
),
'/'
);
}

Expand Down Expand Up @@ -461,7 +468,10 @@ protected function addRedirect($from, $to)
public function handleFolder($basename, $path, $depth)
{
$folder = Injector::inst()->create(
'DocumentationFolder', $this->entity, $basename, $path
'DocumentationFolder',
$this->entity,
$basename,
$path
);

// Add main folder link
Expand Down Expand Up @@ -491,7 +501,9 @@ public function handleFile($basename, $path, $depth)
{
$page = Injector::inst()->create(
'DocumentationPage',
$this->entity, $basename, $path
$this->entity,
$basename,
$path
);

// populate any meta data
Expand Down
2 changes: 1 addition & 1 deletion code/DocumentationManifestFileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DocumentationManifestFileFinder extends SS_FileFinder
);

/**
*
*
*/
public function acceptDir($basename, $pathname, $depth)
{
Expand Down
25 changes: 12 additions & 13 deletions code/DocumentationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public static function rewrite_code_blocks($md)
$inner = true;
}
} elseif (preg_match('/^[\ ]{0,3}?[\t](.*)/', $line, $matches)) {

// inner line of block, or first line of standard markdown code block
// regex removes first tab (any following tabs are part of the code).
if (!$started) {
Expand Down Expand Up @@ -248,7 +247,9 @@ public static function rewrite_image_links($md, $page)
if (substr($url, 0, 1) == '/') {
$relativeUrl = DocumentationHelper::normalizePath(
str_replace(
BASE_PATH, '', Controller::join_links(
BASE_PATH,
'',
Controller::join_links(
$page->getEntity()->getPath(),
$url
)
Expand Down Expand Up @@ -326,11 +327,11 @@ public static function rewrite_api_links($markdown, $doc_page)
$html_format = '<a href="http://api.silverstripe.org/search/lookup/?q=%s&version=%s&module=%s">%s</a>';

// parse api links without backticks into html
foreach($regexs as $type => $regex) {
foreach ($regexs as $type => $regex) {
preg_match_all($regex, $markdown, $links);
if($links) {
foreach($links[0] as $i => $match) {
if($type === 'no_title') {
if ($links) {
foreach ($links[0] as $i => $match) {
if ($type === 'no_title') {
$title = $links[1][$i];
$link = $links[1][$i];
// change backticked links to avoid being parsed in the same way as non-backticked links
Expand All @@ -349,25 +350,24 @@ public static function rewrite_api_links($markdown, $doc_page)

// recover backticked links with no titles
preg_match_all('#XYZ(.*)?XYZ#', $markdown, $links);
if($links) {
foreach($links[0] as $i => $match) {
if ($links) {
foreach ($links[0] as $i => $match) {
$link = $links[1][$i];
$markdown = str_replace($match, '`[api:'.$link.']`', $markdown);
}
}

// recover backticked links with titles
preg_match_all('#XX(.*)?YY(.*)?ZZ#', $markdown, $links);
if($links) {
foreach($links[0] as $i => $match) {
if ($links) {
foreach ($links[0] as $i => $match) {
$title = $links[1][$i];
$link = $links[2][$i];
$markdown = str_replace($match, '`['.$title.'](api:'.$link.')`', $markdown);
}
}

return $markdown;

}

/**
Expand Down Expand Up @@ -488,7 +488,7 @@ public static function rewrite_relative_links($md, $page)
$fileBaseLink,
$url
);
} else if (preg_match('/^#/', $url)) {
} elseif (preg_match('/^#/', $url)) {
// for relative links begining with a hash use the current page link
$relativeUrl = Controller::join_links($baselink, $page->getRelativeLink(), $url);
} else {
Expand Down Expand Up @@ -521,5 +521,4 @@ public static function rewrite_relative_links($md, $page)

return $md;
}

}
4 changes: 2 additions & 2 deletions code/DocumentationPermalinks.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* A mapping store of given permalinks to the full documentation path or useful
* A mapping store of given permalinks to the full documentation path or useful
* for customizing the shortcut URLs used in the viewer.
*
* Redirects the user from example.com/foo to example.com/en/module/foo
Expand All @@ -25,7 +25,7 @@ class DocumentationPermalinks
* ));
* </code>
*
* Do not need to include the language or the version current as it
* Do not need to include the language or the version current as it
* will add it based off the language or version in the session
*
* @param array
Expand Down
17 changes: 9 additions & 8 deletions code/DocumentationSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
require_once 'Zend/Search/Lucene.php';

/**
* Documentation Search powered by Lucene. You will need Zend_Lucene installed
* Documentation Search powered by Lucene. You will need Zend_Lucene installed
* on your path.
*
* To rebuild the indexes run the {@link RebuildLuceneDocsIndex} task. You may
* To rebuild the indexes run the {@link RebuildLuceneDocsIndex} task. You may
* wish to setup a cron job to remake the indexes on a regular basis.
*
* This class has the ability to generate an OpenSearch RSS formatted feeds
* This class has the ability to generate an OpenSearch RSS formatted feeds
* simply by using the URL:
*
* <code>
* yoursite.com/search/?q=Foo&format=rss. // Format can either be specified as rss or left off.
* </code>
*
* To get a specific amount of results you can also use the modifiers start and
* To get a specific amount of results you can also use the modifiers start and
* limit:
*
* <code>
Expand Down Expand Up @@ -127,7 +127,7 @@ public function setOutputController($controller)
* Folder name for indexes (in the temp folder).
*
* @config
* @var string
* @var string
*/
private static $index_location;

Expand Down Expand Up @@ -363,7 +363,7 @@ public function getTitle()
}

/**
* OpenSearch MetaData fields. For a list of fields consult
* OpenSearch MetaData fields. For a list of fields consult
* {@link self::get_meta_data()}
*
* @param array
Expand Down Expand Up @@ -406,7 +406,7 @@ public static function get_meta_data()
}

/**
* Renders the search results into a template. Either the search results
* Renders the search results into a template. Either the search results
* template or the Atom feed.
*/
public function renderResults()
Expand All @@ -428,7 +428,8 @@ public function renderResults()
$title = ($title = $this->getTitle()) ? ' - '. $title : "";

$link = Controller::join_links(
$this->outputController->Link(), 'DocumentationOpenSearchController/description/'
$this->outputController->Link(),
'DocumentationOpenSearchController/description/'
);

$data->setField('Title', $data->Title . $title);
Expand Down
17 changes: 10 additions & 7 deletions code/controllers/DocumentationViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function init()
)
);
Requirements::combine_files(
'docs.css',
'docs.css',
array(
DOCSVIEWER_DIR .'/css/highlight.css',
DOCSVIEWER_DIR .'/css/normalize.css',
Expand Down Expand Up @@ -204,7 +204,8 @@ public function handleAction($request, $action)
// Strip off the base url
//
$base = ltrim(
Config::inst()->get('DocumentationViewer', 'link_base'), '/'
Config::inst()->get('DocumentationViewer', 'link_base'),
'/'
);

if ($base && strpos($url, $base) !== false) {
Expand Down Expand Up @@ -393,7 +394,8 @@ public function getMenu()

// add children
$children = $this->getManifest()->getChildrenFor(
$entity->getPath(), ($record) ? $record->getPath() : $entity->getPath()
$entity->getPath(),
($record) ? $record->getPath() : $entity->getPath()
);
} else {
if ($current && $current->getKey() == $entity->getKey()) {
Expand Down Expand Up @@ -438,7 +440,7 @@ public function getContent()
public function replaceChildrenCalls($html)
{
$codes = new ShortcodeParser();
$codes->register('CHILDREN', array($this, 'includeChildren'));
$codes->register('CHILDREN', array($this, 'includeChildren'));

return $codes->parse($html);
}
Expand Down Expand Up @@ -694,7 +696,6 @@ public function getEditLink()
$entity = $page->getEntity();

if ($entity && isset(self::$edit_links[strtolower($entity->title)])) {

// build the edit link, using the version defined
$url = self::$edit_links[strtolower($entity->title)];
$version = $entity->getVersion();
Expand Down Expand Up @@ -738,7 +739,8 @@ public function getNextPage()
{
return ($this->record)
? $this->getManifest()->getNextPage(
$this->record->getPath(), $this->getEntity()->getPath()
$this->record->getPath(),
$this->getEntity()->getPath()
)
: null;
}
Expand All @@ -753,7 +755,8 @@ public function getPreviousPage()
{
return ($this->record)
? $this->getManifest()->getPreviousPage(
$this->record->getPath(), $this->getEntity()->getPath()
$this->record->getPath(),
$this->getEntity()->getPath()
)
: null;
}
Expand Down
3 changes: 2 additions & 1 deletion code/forms/DocumentationAdvancedSearchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function __construct($controller)
CheckboxSetField::create(
'Versions',
_t('DocumentationViewer.VERSIONS', 'Versions'),
$versions, $searchedVersions
$versions,
$searchedVersions
)
);

Expand Down
4 changes: 2 additions & 2 deletions code/models/DocumentationFolder.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* A specific documentation folder within a {@link DocumentationEntity}.
* A specific documentation folder within a {@link DocumentationEntity}.
*
* Maps to a folder on the file system.
* Maps to a folder on the file system.
*
* @package docsviewer
* @subpackage model
Expand Down
3 changes: 2 additions & 1 deletion code/models/DocumentationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function getBreadcrumbTitle($divider = ' - ')
);

$titleParts = array_filter(
$titleParts, function ($val) {
$titleParts,
function ($val) {
if ($val) {
return $val;
}
Expand Down
Loading

0 comments on commit fe8b9a3

Please sign in to comment.