Page::getIndex()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4286
cc 2
eloc 10
nc 2
nop 2
1
<?php
2
3
class Page extends \BaseController {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
5
  public function getIndex($version, $id = 'installation')
6
  {
7
    $supportedVersions = $this->getSupportedVersions();
8
9
    if(File::exists(base_path()."/docs/$version/$id.md")) {
10
      $page_source = File::get(base_path()."/docs/$version/$id.md");
11
      $pd = new ParsedownExtra();
12
      $page = $this->replaceVersionPlaceholder($version, $pd->text($page_source));
13
      $index = $this->replaceVersionPlaceholder($version, $pd->text(File::get(base_path()."/docs/$version/documentation.md")));
14
    } else {
15
      return Redirect::secure('/');
16
    }
17
18
    return View::make('index', compact('index', 'page', 'version', 'supportedVersions'));
19
  }
20
21
  private function replaceVersionPlaceholder($version, $content)
22
  {
23
    return str_replace('{{version}}', $version, $content);
24
  }
25
26
  private function getSupportedVersions()
27
  {
28
    return [
29
      '5.1' => '5.1',
30
      '5.0' => '5.0',
31
      '4.1' => '4.1'
32
    ];
33
  }
34
}