Passed
Pull Request — master (#38)
by Robbie
02:34
created
src/Reports/BrokenExternalLinksReport.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -18,80 +18,80 @@
 block discarded – undo
18 18
 class BrokenExternalLinksReport extends Report
19 19
 {
20 20
 
21
-    /**
22
-     * Returns the report title
23
-     *
24
-     * @return string
25
-     */
26
-    public function title()
27
-    {
28
-        return _t(__CLASS__ . '.EXTERNALBROKENLINKS', "External broken links report");
29
-    }
21
+	/**
22
+	 * Returns the report title
23
+	 *
24
+	 * @return string
25
+	 */
26
+	public function title()
27
+	{
28
+		return _t(__CLASS__ . '.EXTERNALBROKENLINKS', "External broken links report");
29
+	}
30 30
 
31
-    public function columns()
32
-    {
33
-        return array(
34
-            "Created" => "Checked",
35
-            'Link' => array(
36
-                'title' => 'External Link',
37
-                'formatting' => function ($value, $item) {
38
-                    return sprintf(
39
-                        '<a target="_blank" href="%s">%s</a>',
40
-                        Convert::raw2att($item->Link),
41
-                        Convert::raw2xml($item->Link)
42
-                    );
43
-                }
44
-            ),
45
-            'HTTPCodeDescription' => 'HTTP Error Code',
46
-            "Title" => array(
47
-                "title" => 'Page link is on',
48
-                'formatting' => function ($value, $item) {
49
-                    $page = $item->Page();
50
-                    return sprintf(
51
-                        '<a href="%s">%s</a>',
52
-                        Convert::raw2att($page->CMSEditLink()),
53
-                        Convert::raw2xml($page->Title)
54
-                    );
55
-                }
56
-            )
57
-        );
58
-    }
31
+	public function columns()
32
+	{
33
+		return array(
34
+			"Created" => "Checked",
35
+			'Link' => array(
36
+				'title' => 'External Link',
37
+				'formatting' => function ($value, $item) {
38
+					return sprintf(
39
+						'<a target="_blank" href="%s">%s</a>',
40
+						Convert::raw2att($item->Link),
41
+						Convert::raw2xml($item->Link)
42
+					);
43
+				}
44
+			),
45
+			'HTTPCodeDescription' => 'HTTP Error Code',
46
+			"Title" => array(
47
+				"title" => 'Page link is on',
48
+				'formatting' => function ($value, $item) {
49
+					$page = $item->Page();
50
+					return sprintf(
51
+						'<a href="%s">%s</a>',
52
+						Convert::raw2att($page->CMSEditLink()),
53
+						Convert::raw2xml($page->Title)
54
+					);
55
+				}
56
+			)
57
+		);
58
+	}
59 59
 
60
-    /**
61
-     * Alias of columns(), to support the export to csv action
62
-     * in {@link GridFieldExportButton} generateExportFileData method.
63
-     * @return array
64
-     */
65
-    public function getColumns()
66
-    {
67
-        return $this->columns();
68
-    }
60
+	/**
61
+	 * Alias of columns(), to support the export to csv action
62
+	 * in {@link GridFieldExportButton} generateExportFileData method.
63
+	 * @return array
64
+	 */
65
+	public function getColumns()
66
+	{
67
+		return $this->columns();
68
+	}
69 69
 
70
-    public function sourceRecords()
71
-    {
72
-        $track = BrokenExternalPageTrackStatus::get_latest();
73
-        if ($track) {
74
-            return $track->BrokenLinks();
75
-        }
76
-        return ArrayList::create();
77
-    }
70
+	public function sourceRecords()
71
+	{
72
+		$track = BrokenExternalPageTrackStatus::get_latest();
73
+		if ($track) {
74
+			return $track->BrokenLinks();
75
+		}
76
+		return ArrayList::create();
77
+	}
78 78
 
79
-    public function getCMSFields()
80
-    {
81
-        Requirements::css('silverstripe/externallinks: css/BrokenExternalLinksReport.css');
82
-        Requirements::javascript('silverstripe/externallinks: javascript/BrokenExternalLinksReport.js');
79
+	public function getCMSFields()
80
+	{
81
+		Requirements::css('silverstripe/externallinks: css/BrokenExternalLinksReport.css');
82
+		Requirements::javascript('silverstripe/externallinks: javascript/BrokenExternalLinksReport.js');
83 83
 
84
-        $fields = parent::getCMSFields();
84
+		$fields = parent::getCMSFields();
85 85
 
86
-        $runReportButton = FormAction::create('createReport', _t(__CLASS__ . '.RUNREPORT', 'Create new report'))
87
-            ->addExtraClass('btn-primary external-links-report__create-report')
88
-            ->setUseButtonTag(true);
89
-        $fields->push($runReportButton);
86
+		$runReportButton = FormAction::create('createReport', _t(__CLASS__ . '.RUNREPORT', 'Create new report'))
87
+			->addExtraClass('btn-primary external-links-report__create-report')
88
+			->setUseButtonTag(true);
89
+		$fields->push($runReportButton);
90 90
 
91
-        $reportResultSpan = '<p class="external-links-report__report-progress"></p>';
92
-        $reportResult = LiteralField::create('ResultTitle', $reportResultSpan);
93
-        $fields->push($reportResult);
91
+		$reportResultSpan = '<p class="external-links-report__report-progress"></p>';
92
+		$reportResult = LiteralField::create('ResultTitle', $reportResultSpan);
93
+		$fields->push($reportResult);
94 94
 
95
-        return $fields;
96
-    }
95
+		return $fields;
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public function title()
27 27
     {
28
-        return _t(__CLASS__ . '.EXTERNALBROKENLINKS', "External broken links report");
28
+        return _t(__CLASS__.'.EXTERNALBROKENLINKS', "External broken links report");
29 29
     }
30 30
 
31 31
     public function columns()
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
             "Created" => "Checked",
35 35
             'Link' => array(
36 36
                 'title' => 'External Link',
37
-                'formatting' => function ($value, $item) {
37
+                'formatting' => function($value, $item) {
38 38
                     return sprintf(
39 39
                         '<a target="_blank" href="%s">%s</a>',
40 40
                         Convert::raw2att($item->Link),
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             'HTTPCodeDescription' => 'HTTP Error Code',
46 46
             "Title" => array(
47 47
                 "title" => 'Page link is on',
48
-                'formatting' => function ($value, $item) {
48
+                'formatting' => function($value, $item) {
49 49
                     $page = $item->Page();
50 50
                     return sprintf(
51 51
                         '<a href="%s">%s</a>',
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
         $fields = parent::getCMSFields();
85 85
 
86
-        $runReportButton = FormAction::create('createReport', _t(__CLASS__ . '.RUNREPORT', 'Create new report'))
86
+        $runReportButton = FormAction::create('createReport', _t(__CLASS__.'.RUNREPORT', 'Create new report'))
87 87
             ->addExtraClass('btn-primary external-links-report__create-report')
88 88
             ->setUseButtonTag(true);
89 89
         $fields->push($runReportButton);
Please login to merge, or discard this patch.
src/Tasks/CurlLinkChecker.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -11,47 +11,47 @@
 block discarded – undo
11 11
 class CurlLinkChecker implements LinkChecker
12 12
 {
13 13
 
14
-    /**
15
-     * Return cache
16
-     *
17
-     * @return CacheInterface
18
-     */
19
-    protected function getCache()
20
-    {
21
-        return Injector::inst()->get(CacheInterface::class . '.CurlLinkChecker');
22
-    }
23
-
24
-    /**
25
-     * Determine the http status code for a given link
26
-     *
27
-     * @param string $href URL to check
28
-     * @return int HTTP status code, or null if not checkable (not a link)
29
-     */
30
-    public function checkLink($href)
31
-    {
32
-        // Skip non-external links
33
-        if (!preg_match('/^https?[^:]*:\/\//', $href)) {
34
-            return null;
35
-        }
36
-
37
-        // Check if we have a cached result
38
-        $cacheKey = md5($href);
39
-        $result = $this->getCache()->get($cacheKey, false);
40
-        if ($result !== false) {
41
-            return $result;
42
-        }
43
-
44
-        // No cached result so just request
45
-        $handle = curl_init($href);
46
-        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
47
-        curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
48
-        curl_setopt($handle, CURLOPT_TIMEOUT, 10);
49
-        curl_exec($handle);
50
-        $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
51
-        curl_close($handle);
52
-
53
-        // Cache result
54
-        $this->getCache()->set($cacheKey, $httpCode);
55
-        return $httpCode;
56
-    }
14
+	/**
15
+	 * Return cache
16
+	 *
17
+	 * @return CacheInterface
18
+	 */
19
+	protected function getCache()
20
+	{
21
+		return Injector::inst()->get(CacheInterface::class . '.CurlLinkChecker');
22
+	}
23
+
24
+	/**
25
+	 * Determine the http status code for a given link
26
+	 *
27
+	 * @param string $href URL to check
28
+	 * @return int HTTP status code, or null if not checkable (not a link)
29
+	 */
30
+	public function checkLink($href)
31
+	{
32
+		// Skip non-external links
33
+		if (!preg_match('/^https?[^:]*:\/\//', $href)) {
34
+			return null;
35
+		}
36
+
37
+		// Check if we have a cached result
38
+		$cacheKey = md5($href);
39
+		$result = $this->getCache()->get($cacheKey, false);
40
+		if ($result !== false) {
41
+			return $result;
42
+		}
43
+
44
+		// No cached result so just request
45
+		$handle = curl_init($href);
46
+		curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
47
+		curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
48
+		curl_setopt($handle, CURLOPT_TIMEOUT, 10);
49
+		curl_exec($handle);
50
+		$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
51
+		curl_close($handle);
52
+
53
+		// Cache result
54
+		$this->getCache()->set($cacheKey, $httpCode);
55
+		return $httpCode;
56
+	}
57 57
 }
Please login to merge, or discard this patch.
src/Controllers/CMSExternalLinksController.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -13,62 +13,62 @@
 block discarded – undo
13 13
 class CMSExternalLinksController extends Controller
14 14
 {
15 15
 
16
-    private static $allowed_actions = [
17
-        'getJobStatus',
18
-        'start'
19
-    ];
16
+	private static $allowed_actions = [
17
+		'getJobStatus',
18
+		'start'
19
+	];
20 20
 
21
-    /**
22
-     * Respond to Ajax requests for info on a running job
23
-     *
24
-     * @return string JSON string detailing status of the job
25
-     */
26
-    public function getJobStatus()
27
-    {
28
-        // Set headers
29
-        HTTP::set_cache_age(0);
30
-        HTTP::add_cache_headers($this->response);
31
-        $this->response
32
-            ->addHeader('Content-Type', 'application/json')
33
-            ->addHeader('Content-Encoding', 'UTF-8')
34
-            ->addHeader('X-Content-Type-Options', 'nosniff');
21
+	/**
22
+	 * Respond to Ajax requests for info on a running job
23
+	 *
24
+	 * @return string JSON string detailing status of the job
25
+	 */
26
+	public function getJobStatus()
27
+	{
28
+		// Set headers
29
+		HTTP::set_cache_age(0);
30
+		HTTP::add_cache_headers($this->response);
31
+		$this->response
32
+			->addHeader('Content-Type', 'application/json')
33
+			->addHeader('Content-Encoding', 'UTF-8')
34
+			->addHeader('X-Content-Type-Options', 'nosniff');
35 35
 
36
-        // Format status
37
-        $track = BrokenExternalPageTrackStatus::get_latest();
38
-        if ($track) {
39
-            return Convert::array2json([
40
-                'TrackID' => $track->ID,
41
-                'Status' => $track->Status,
42
-                'Completed' => $track->getCompletedPages(),
43
-                'Total' => $track->getTotalPages()
44
-            ]);
45
-        }
46
-    }
36
+		// Format status
37
+		$track = BrokenExternalPageTrackStatus::get_latest();
38
+		if ($track) {
39
+			return Convert::array2json([
40
+				'TrackID' => $track->ID,
41
+				'Status' => $track->Status,
42
+				'Completed' => $track->getCompletedPages(),
43
+				'Total' => $track->getTotalPages()
44
+			]);
45
+		}
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * Starts a broken external link check
51
-     */
52
-    public function start()
53
-    {
54
-        // return if the a job is already running
55
-        $status = BrokenExternalPageTrackStatus::get_latest();
56
-        if ($status && $status->Status == 'Running') {
57
-            return;
58
-        }
49
+	/**
50
+	 * Starts a broken external link check
51
+	 */
52
+	public function start()
53
+	{
54
+		// return if the a job is already running
55
+		$status = BrokenExternalPageTrackStatus::get_latest();
56
+		if ($status && $status->Status == 'Running') {
57
+			return;
58
+		}
59 59
 
60
-        // Create a new job
61
-        if (class_exists(QueuedJobService::class)) {
62
-            // Force the creation of a new run
63
-            BrokenExternalPageTrackStatus::create_status();
64
-            $checkLinks = new CheckExternalLinksJob();
65
-            singleton(QueuedJobService::class)->queueJob($checkLinks);
66
-        } else {
67
-            //TODO this hangs as it waits for the connection to be released
68
-            // should return back and continue processing
69
-            // http://us3.php.net/manual/en/features.connection-handling.php
70
-            $task = CheckExternalLinksTask::create();
71
-            $task->runLinksCheck();
72
-        }
73
-    }
60
+		// Create a new job
61
+		if (class_exists(QueuedJobService::class)) {
62
+			// Force the creation of a new run
63
+			BrokenExternalPageTrackStatus::create_status();
64
+			$checkLinks = new CheckExternalLinksJob();
65
+			singleton(QueuedJobService::class)->queueJob($checkLinks);
66
+		} else {
67
+			//TODO this hangs as it waits for the connection to be released
68
+			// should return back and continue processing
69
+			// http://us3.php.net/manual/en/features.connection-handling.php
70
+			$task = CheckExternalLinksTask::create();
71
+			$task->runLinksCheck();
72
+		}
73
+	}
74 74
 }
Please login to merge, or discard this patch.