Fix some CBF linting issues. Improved a couple of doc blocks.

This commit is contained in:
Robbie Averill 2016-12-05 08:53:53 +13:00
parent a9130a33db
commit 909cfd695f
9 changed files with 178 additions and 153 deletions

View File

@ -30,11 +30,11 @@ class DocumentationParser
* Pathparts: folder/subfolder/page * Pathparts: folder/subfolder/page
* *
* @param DocumentationPage $page * @param DocumentationPage $page
* @param String $baselink Link relative to webroot, up until the "root" of the module. Necessary to rewrite relative links * @param string $baselink Link relative to webroot, up until the "root" of the module.
* of the module. Necessary to rewrite relative * Necessary to rewrite relative links of the module. Necessary
* links * to rewrite relative links
* *
* @return String * @return string
*/ */
public static function parse(DocumentationPage $page, $baselink = null) public static function parse(DocumentationPage $page, $baselink = null)
{ {

View File

@ -658,8 +658,6 @@ class DocumentationViewer extends Controller implements PermissionProvider
if ($page) { if ($page) {
$entity = $page->getEntity(); $entity = $page->getEntity();
if ($entity && isset(self::$edit_links[strtolower($entity->title)])) { if ($entity && isset(self::$edit_links[strtolower($entity->title)])) {
// build the edit link, using the version defined // build the edit link, using the version defined
@ -671,7 +669,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
} }
if ($version == "trunk" && (isset($url['options']['rewritetrunktomaster']))) { if ($version == 'trunk' && (isset($url['options']['rewritetrunktomaster']))) {
if ($url['options']['rewritetrunktomaster']) { if ($url['options']['rewritetrunktomaster']) {
$version = "master"; $version = "master";
} }
@ -699,7 +697,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
* Returns the next page. Either retrieves the sibling of the current page * Returns the next page. Either retrieves the sibling of the current page
* or return the next sibling of the parent page. * or return the next sibling of the parent page.
* *
* @return DocumentationPage * @return DocumentationPage|null
*/ */
public function getNextPage() public function getNextPage()
{ {
@ -714,7 +712,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
* Returns the previous page. Either returns the previous sibling or the * Returns the previous page. Either returns the previous sibling or the
* parent of this page * parent of this page
* *
* @return DocumentationPage * @return DocumentationPage|null
*/ */
public function getPreviousPage() public function getPreviousPage()
{ {
@ -726,7 +724,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
} }
/** /**
* @return string * @return string|void
*/ */
public function getGoogleAnalyticsCode() public function getGoogleAnalyticsCode()
{ {
@ -745,6 +743,9 @@ class DocumentationViewer extends Controller implements PermissionProvider
return $this->config()->get('documentation_title'); return $this->config()->get('documentation_title');
} }
/**
* @return string
*/
public function getDocumentationBaseHref() public function getDocumentationBaseHref()
{ {
return Config::inst()->get('DocumentationViewer', 'link_base'); return Config::inst()->get('DocumentationViewer', 'link_base');

View File

@ -1,14 +1,15 @@
<?php <?php
/**
* @package docsviewer
*/
class DocumentationViewerVersionWarning extends Extension
{
/** /**
* Check to see if the currently accessed version is out of date or perhaps a * Check to see if the currently accessed version is out of date or perhaps a
* future version rather than the stable edition. * future version rather than the stable edition.
* *
* @return false|ArrayData * @return false|ArrayData
*/ */
class DocumentationViewerVersionWarning extends Extension
{
public function VersionWarning() public function VersionWarning()
{ {
$page = $this->owner->getPage(); $page = $this->owner->getPage();
@ -32,7 +33,7 @@ class DocumentationViewerVersionWarning extends Extension
$stable = $this->owner->getManifest()->getStableVersion($entity); $stable = $this->owner->getManifest()->getStableVersion($entity);
$compare = $entity->compare($stable); $compare = $entity->compare($stable);
if ($entity->getVersion() == "master" || $compare > 0) { if ($entity->getVersion() == 'master' || $compare > 0) {
return $this->owner->customise( return $this->owner->customise(
new ArrayData( new ArrayData(
array( array(

View File

@ -321,7 +321,6 @@ class DocumentationEntity extends ViewableData
/** /**
* @param string $path * @param string $path
*
* @return $this * @return $this
*/ */
public function setPath($path) public function setPath($path)
@ -350,8 +349,6 @@ class DocumentationEntity extends ViewableData
return $this->stable; return $this->stable;
} }
/** /**
* Returns an integer value based on if a given version is the latest * Returns an integer value based on if a given version is the latest
* version. Will return -1 for if the version is older, 0 if versions are * version. Will return -1 for if the version is older, 0 if versions are

View File

@ -73,8 +73,10 @@ class DocumentationPage extends ViewableData
$titleParts = array_map( $titleParts = array_map(
array( array(
'DocumentationHelper', 'clean_page_name' 'DocumentationHelper',
), $pathParts 'clean_page_name'
),
$pathParts
); );
$titleParts = array_filter( $titleParts = array_filter(
@ -111,7 +113,7 @@ class DocumentationPage extends ViewableData
$page = DocumentationHelper::clean_page_name($this->filename); $page = DocumentationHelper::clean_page_name($this->filename);
if ($page == "Index") { if ($page == 'Index') {
return $this->getTitleFromFolder(); return $this->getTitleFromFolder();
} }
@ -150,7 +152,7 @@ class DocumentationPage extends ViewableData
* *
* @param boolean $removeMetaData * @param boolean $removeMetaData
* *
* @return string * @return string|false
*/ */
public function getMarkdown($removeMetaData = false) public function getMarkdown($removeMetaData = false)
{ {
@ -175,6 +177,9 @@ class DocumentationPage extends ViewableData
$this->$key = $value; $this->$key = $value;
} }
/**
* @return string
*/
public function getIntroduction() public function getIntroduction()
{ {
if (!$this->read) { if (!$this->read) {
@ -213,10 +218,12 @@ class DocumentationPage extends ViewableData
$path = $this->getRelativePath(); $path = $this->getRelativePath();
$url = explode('/', $path); $url = explode('/', $path);
$url = implode( $url = implode(
'/', array_map( '/',
array_map(
function ($a) { function ($a) {
return DocumentationHelper::clean_page_url($a); return DocumentationHelper::clean_page_url($a);
}, $url },
$url
) )
); );
@ -307,6 +314,9 @@ class DocumentationPage extends ViewableData
return $this->entity->getVersion(); return $this->entity->getVersion();
} }
/**
* @return string
*/
public function __toString() public function __toString()
{ {
return sprintf(get_class($this) .': %s)', $this->getPath()); return sprintf(get_class($this) .': %s)', $this->getPath());

View File

@ -9,7 +9,8 @@ class DocumentationHelperTests extends SapphireTest
public function testCleanName() public function testCleanName()
{ {
$this->assertEquals( $this->assertEquals(
"File path", DocumentationHelper::clean_page_name( 'File path',
DocumentationHelper::clean_page_name(
'00_file-path.md' '00_file-path.md'
) )
); );
@ -18,13 +19,15 @@ class DocumentationHelperTests extends SapphireTest
public function testCleanUrl() public function testCleanUrl()
{ {
$this->assertEquals( $this->assertEquals(
"some_path", DocumentationHelper::clean_page_url( 'some_path',
DocumentationHelper::clean_page_url(
'Some Path' 'Some Path'
) )
); );
$this->assertEquals( $this->assertEquals(
"somefilepath", DocumentationHelper::clean_page_url( 'somefilepath',
DocumentationHelper::clean_page_url(
'00_SomeFilePath.md' '00_SomeFilePath.md'
) )
); );
@ -33,19 +36,22 @@ class DocumentationHelperTests extends SapphireTest
public function testTrimSortNumber() public function testTrimSortNumber()
{ {
$this->assertEquals( $this->assertEquals(
'file', DocumentationHelper::trim_sort_number( 'file',
DocumentationHelper::trim_sort_number(
'0_file' '0_file'
) )
); );
$this->assertEquals( $this->assertEquals(
'2.1', DocumentationHelper::trim_sort_number( '2.1',
DocumentationHelper::trim_sort_number(
'2.1' '2.1'
) )
); );
$this->assertEquals( $this->assertEquals(
'dev/tasks/2.1', DocumentationHelper::trim_sort_number( 'dev/tasks/2.1',
DocumentationHelper::trim_sort_number(
'dev/tasks/2.1' 'dev/tasks/2.1'
) )
); );
@ -54,13 +60,15 @@ class DocumentationHelperTests extends SapphireTest
public function testTrimExtension() public function testTrimExtension()
{ {
$this->assertEquals( $this->assertEquals(
'file', DocumentationHelper::trim_extension_off( 'file',
DocumentationHelper::trim_extension_off(
'file.md' 'file.md'
) )
); );
$this->assertEquals( $this->assertEquals(
'dev/path/file', DocumentationHelper::trim_extension_off( 'dev/path/file',
DocumentationHelper::trim_extension_off(
'dev/path/file.md' 'dev/path/file.md'
) )
); );
@ -69,19 +77,22 @@ class DocumentationHelperTests extends SapphireTest
public function testGetExtension() public function testGetExtension()
{ {
$this->assertEquals( $this->assertEquals(
'md', DocumentationHelper::get_extension( 'md',
DocumentationHelper::get_extension(
'file.md' 'file.md'
) )
); );
$this->assertEquals( $this->assertEquals(
'md', DocumentationHelper::get_extension( 'md',
DocumentationHelper::get_extension(
'dev/tasks/file.md' 'dev/tasks/file.md'
) )
); );
$this->assertEquals( $this->assertEquals(
'txt', DocumentationHelper::get_extension( 'txt',
DocumentationHelper::get_extension(
'dev/tasks/file.txt' 'dev/tasks/file.txt'
) )
); );

View File

@ -108,7 +108,8 @@ class DocumentationManifestTests extends SapphireTest
// get next page at the end of one subfolder goes back up to the top // get next page at the end of one subfolder goes back up to the top
// most directory // most directory
$this->assertStringEndsWith( $this->assertStringEndsWith(
'2.3/test/', $this->manifest->getNextPage( '2.3/test/',
$this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs/en/subfolder/subsubfolder/subsubpage.md', DOCSVIEWER_PATH . '/tests/docs/en/subfolder/subsubfolder/subsubpage.md',
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link )->Link
@ -116,7 +117,8 @@ class DocumentationManifestTests extends SapphireTest
// after sorting, 2 is shown. // after sorting, 2 is shown.
$this->assertContains( $this->assertContains(
'/intermediate/', $this->manifest->getNextPage( '/intermediate/',
$this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs/en/sort/01-basic.md', DOCSVIEWER_PATH . '/tests/docs/en/sort/01-basic.md',
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link )->Link
@ -125,7 +127,8 @@ class DocumentationManifestTests extends SapphireTest
// next gets the following URL // next gets the following URL
$this->assertContains( $this->assertContains(
'/test/', $this->manifest->getNextPage( '/test/',
$this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs-v2.4/en/index.md', DOCSVIEWER_PATH . '/tests/docs-v2.4/en/index.md',
DOCSVIEWER_PATH . '/tests/docs-v2.4/en/' DOCSVIEWER_PATH . '/tests/docs-v2.4/en/'
)->Link )->Link
@ -145,7 +148,8 @@ class DocumentationManifestTests extends SapphireTest
{ {
// goes right into subfolders // goes right into subfolders
$this->assertContains( $this->assertContains(
'subfolder/subsubfolder/subsubpage', $this->manifest->getPreviousPage( 'subfolder/subsubfolder/subsubpage',
$this->manifest->getPreviousPage(
DOCSVIEWER_PATH . '/tests/docs/en/test.md', DOCSVIEWER_PATH . '/tests/docs/en/test.md',
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link )->Link
@ -186,7 +190,7 @@ class DocumentationManifestTests extends SapphireTest
$this->assertDOSContains( $this->assertDOSContains(
$expected, $this->manifest->getChildrenFor( $expected, $this->manifest->getChildrenFor(
DOCSVIEWER_PATH . "/tests/docs/en/" DOCSVIEWER_PATH . '/tests/docs/en/'
) )
); );
@ -197,7 +201,8 @@ class DocumentationManifestTests extends SapphireTest
); );
$this->assertDOSContains( $this->assertDOSContains(
$expected, $this->manifest->getChildrenFor( $expected,
$this->manifest->getChildrenFor(
DOCSVIEWER_PATH . '/tests/docs-v3.0/en/', DOCSVIEWER_PATH . '/tests/docs-v3.0/en/',
DOCSVIEWER_PATH . '/tests/docs-v3.0/en/ChangeLog.md' DOCSVIEWER_PATH . '/tests/docs-v3.0/en/ChangeLog.md'
) )