Passed
Push — develop ( 1545da...3f2ac7 )
by Dylan
02:45
created
code/extenstions/SEOToolboxControllerExtension.php 1 patch
Braces   +32 added lines, -13 removed lines patch added patch discarded remove patch
@@ -84,12 +84,16 @@  discard block
 block discarded – undo
84 84
     private function getSettings() {
85 85
         if ($this->settings === null) {
86 86
             $this->settings = GlobalAutoLinkSettings::get_current();
87
-            if (!$this->settings) return $this->addLinks = false;
87
+            if (!$this->settings) {
88
+                return $this->addLinks = false;
89
+            }
88 90
 
89 91
             $this->excludeTags = (array) $this->settings->ExcludeTags();
90 92
             $this->maxLinks = (int) ($this->settings->MaxLinksPerPage) ? $this->settings->MaxLinksPerPage : PHP_INT_MAX;
91 93
 
92
-            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) $this->addLinks = false;
94
+            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) {
95
+                $this->addLinks = false;
96
+            }
93 97
         }
94 98
 
95 99
         return $this->settings;
@@ -153,7 +157,9 @@  discard block
 block discarded – undo
153 157
         $excluded = array();
154 158
         foreach( $this->excludeTags as $eTag ){
155 159
             while( $tags = $html->getElementsByTagName( $eTag ) ){
156
-                if( !$tags->length ) break 1;
160
+                if( !$tags->length ) {
161
+                    break 1;
162
+                }
157 163
                 $tag	= $tags->item(0);
158 164
                 $value  = $html->saveHTML( $tag );
159 165
                 $key    = (string) crc32( $value );
@@ -172,7 +178,9 @@  discard block
 block discarded – undo
172 178
         $links = AutomatedLink::get()->sort('Priority');
173 179
         foreach( $links as $link ){
174 180
             // Check if self-linking is allowed and if current pagetype is allowed
175
-            if( !$link->canBeAdded( $this->owner, $field ) ) continue;
181
+            if( !$link->canBeAdded( $this->owner, $field ) ) {
182
+                continue;
183
+            }
176 184
 
177 185
             $max    = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX;
178 186
             $escape = (string) preg_quote( $link->Phrase, '/' );
@@ -181,22 +189,31 @@  discard block
 block discarded – undo
181 189
             // Count the matches
182 190
             preg_match_all( $regex, $content, $count );
183 191
             $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
184
-            if( $count < 1 ) continue;
192
+            if( $count < 1 ) {
193
+                continue;
194
+            }
185 195
 
186
-            if( isset( $this->maxLinksPerPage[ $link->ID ] ) )
187
-                $max -= $this->maxLinksPerPage[ $link->ID ];
188
-            else
189
-                $this->maxLinksPerPage[ $link->ID ] = 0;
196
+            if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) {
197
+                            $max -= $this->maxLinksPerPage[ $link->ID ];
198
+            } else {
199
+                            $this->maxLinksPerPage[ $link->ID ] = 0;
200
+            }
190 201
 
191 202
             for( $x = 0; $x < $count; $x++ ){
192 203
                 // Stop adding links if we reached the link or page limit
193
-                if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
204
+                if( $x >= $max || $this->linkCount >= $this->maxLinks ) {
205
+                    break;
206
+                }
194 207
 
195 208
                 // Check if there is anything else to replace else stop
196 209
                 preg_match( $regex, $content, $match );
197
-                if( !is_array( $match ) || !count( $match ) ) break;
210
+                if( !is_array( $match ) || !count( $match ) ) {
211
+                    break;
212
+                }
198 213
 
199
-                if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
214
+                if( !$html = (string) $link->getHTML( $match[0] ) ) {
215
+                    continue;
216
+                }
200 217
                 $key              = (string) crc32( $html );
201 218
                 $excluded[ $key ] = (string) $html;
202 219
 
@@ -206,7 +223,9 @@  discard block
 block discarded – undo
206 223
             }
207 224
 
208 225
             // Stop Adding links if we reached the page limit
209
-            if( $this->linkCount >= $this->maxLinks ) break;
226
+            if( $this->linkCount >= $this->maxLinks ) {
227
+                break;
228
+            }
210 229
         }
211 230
 
212 231
         // Re-add the excluded Tags
Please login to merge, or discard this patch.
code/dataobjects/AutomatedLinkPageResult.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public static function add_or_update(SiteTree $page) {
54 54
         $obj = self::get()->find('PageID', $page->ID);
55
-        if (!$obj) $obj = self::create(array('PageID' => $page->ID));
55
+        if (!$obj) {
56
+            $obj = self::create(array('PageID' => $page->ID));
57
+        }
56 58
 
57 59
         $obj->OriginalLinkCount = $page->OriginalLinkCount;
58 60
         $obj->LinksCreatedCount = $page->LinkCount;
@@ -68,6 +70,8 @@  discard block
 block discarded – undo
68 70
      * @return void
69 71
      */
70 72
     public static function remove_old_data() {
71
-        foreach (self::get() as $obj) if (!SiteTree::get()->byID($obj->PageID)) $obj->delete();
73
+        foreach (self::get() as $obj) {
74
+            if (!SiteTree::get()->byID($obj->PageID)) $obj->delete();
75
+        }
72 76
     }
73 77
 }
Please login to merge, or discard this patch.
code/dataobjects/GlobalAutoLinkSettings.php 1 patch
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,8 +61,9 @@  discard block
 block discarded – undo
61 61
         $alpha = 'abcdefghijklm[)0123456789(]nopqrstuvwxyz';
62 62
         $alpha_len = strlen($alpha);
63 63
 
64
-        while (strlen($ret) < 14)
65
-            $ret .= (rand(0, 1) == 0) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)];
64
+        while (strlen($ret) < 14) {
65
+                    $ret .= (rand(0, 1) == 0) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)];
66
+        }
66 67
 
67 68
         return $ret;
68 69
     }
@@ -77,7 +78,9 @@  discard block
 block discarded – undo
77 78
      */
78 79
         public function AllowedIn(){
79 80
         $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) );
80
-        if( !$this->AddTo ) return $classes;
81
+        if( !$this->AddTo ) {
82
+            return $classes;
83
+        }
81 84
 
82 85
         $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) );
83 86
 
@@ -92,7 +95,9 @@  discard block
 block discarded – undo
92 95
                 }
93 96
             }
94 97
 
95
-            if( !$found ) unset( $sanitized[$x] );
98
+            if( !$found ) {
99
+                unset( $sanitized[$x] );
100
+            }
96 101
         }
97 102
 
98 103
         return (array) $sanitized;
Please login to merge, or discard this patch.
code/controllers/SEOTestSiteTreeController.php 1 patch
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,21 +17,29 @@  discard block
 block discarded – undo
17 17
         parent::init();
18 18
 
19 19
         // Check user is logged in and has permission to access to SEO Toolbox Admin
20
-        if (!Member::currentUser()) return $this->redirect(Security::login_url().'?BackURL=/seotest');
21
-        if (!Permission::check('CMS_ACCESS_SEOToolboxAdmin')) return $this->redirect(self::getPermissionDeniedPage()->Link());
20
+        if (!Member::currentUser()) {
21
+            return $this->redirect(Security::login_url().'?BackURL=/seotest');
22
+        }
23
+        if (!Permission::check('CMS_ACCESS_SEOToolboxAdmin')) {
24
+            return $this->redirect(self::getPermissionDeniedPage()->Link());
25
+        }
22 26
 
23 27
         Requirements::clear();
24 28
 
25 29
         // Sprite Location needs to be dynamic as devs can install module in different locations
26 30
         $sprite_path = $this->config()->get('sprite_path');
27
-        if ($sprite_path === null) $sprite_path = SEOTOOLBOX_DIR.'/css/icons/icon_sprite.png';
31
+        if ($sprite_path === null) {
32
+            $sprite_path = SEOTOOLBOX_DIR.'/css/icons/icon_sprite.png';
33
+        }
28 34
         Requirements::customCSS(".icon{width:16px;height: 16px;cursor:pointer;background: url(/{$sprite_path});}");
29 35
 
30 36
         // CSS can be replaced by devs if they desire to change styling
31 37
         Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap.min.css');
32 38
         Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap-theme.min.css');
33 39
         $css = $this->config()->get('css');
34
-        if ($css === null) $css = array(SEOTOOLBOX_DIR.'/fonts/lato/lato.css', SEOTOOLBOX_DIR.'/css/seotest.css');
40
+        if ($css === null) {
41
+            $css = array(SEOTOOLBOX_DIR.'/fonts/lato/lato.css', SEOTOOLBOX_DIR.'/css/seotest.css');
42
+        }
35 43
         Requirements::combine_files('seotest.css', $css);
36 44
 
37 45
         Requirements::combine_files('seotest.js', array(
@@ -120,8 +128,9 @@  discard block
 block discarded – undo
120 128
                 $phrases = array_merge($phrases, $matches[$commands['find_pos']]);
121 129
             }
122 130
 
123
-            if (isset($commands['replace']))
124
-                $html = preg_replace($commands['replace'], ' ', $html);
131
+            if (isset($commands['replace'])) {
132
+                            $html = preg_replace($commands['replace'], ' ', $html);
133
+            }
125 134
         }
126 135
 
127 136
         // Remove the empty elements
Please login to merge, or discard this patch.
code/dataobjects/AutomatedLink.php 1 patch
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -263,7 +263,7 @@
 block discarded – undo
263 263
                 while($html5->length > 0) {
264 264
                     $dom->appendChild($html5->item(0));
265 265
                 }
266
-            }else{
266
+            } else{
267 267
                 $dom = $html5;
268 268
             }
269 269
         } else{
Please login to merge, or discard this patch.
code/controllers/AutomatedLinkReportTask.php 1 patch
Braces   +36 added lines, -15 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
     private static $exclude_classes = array('RedirectorPage', 'VirtualPage');
17 17
 
18 18
     public function index() {
19
-        if (!Director::is_cli()) return 'Please run this controller in CLI';
19
+        if (!Director::is_cli()) {
20
+            return 'Please run this controller in CLI';
21
+        }
20 22
 
21 23
         libxml_use_internal_errors(true);
22 24
         set_time_limit(600);
@@ -52,15 +54,23 @@  discard block
 block discarded – undo
52 54
         $exclude = Config::inst()->get($this->class, 'exclude_classes');
53 55
         $exclude = ($exclude) ? "'".implode("','", $exclude)."'" : '';
54 56
         foreach (SiteTree::get()->where("ClassName NOT IN($exclude)") as $page) {
55
-            if (!$this->checkForPossibleLinks($page, $includeInFields)) continue;
57
+            if (!$this->checkForPossibleLinks($page, $includeInFields)) {
58
+                continue;
59
+            }
56 60
             $page = $this->getLinkData($page, $includeInFields);
57
-            if (!$page) continue;
61
+            if (!$page) {
62
+                continue;
63
+            }
58 64
 
59
-            if (!$run_in_realtime) AutomatedLinkPageResult::add_or_update($page);
65
+            if (!$run_in_realtime) {
66
+                AutomatedLinkPageResult::add_or_update($page);
67
+            }
60 68
             $data->push($page);
61 69
         }
62 70
 
63
-        if (!$run_in_realtime) AutomatedLinkPageResult::remove_old_data();
71
+        if (!$run_in_realtime) {
72
+            AutomatedLinkPageResult::remove_old_data();
73
+        }
64 74
 
65 75
         return $data;
66 76
     }
@@ -78,15 +88,18 @@  discard block
 block discarded – undo
78 88
         // Set a list of all fields that can have autolinks created in them
79 89
         $page->AutomateableFields = ArrayList::create();
80 90
 
81
-        foreach (AutomatedLink::getAllDatabaseFields($page->class) as $field => $type)
82
-            if (in_array($field, $includeIn) &&
91
+        foreach (AutomatedLink::getAllDatabaseFields($page->class) as $field => $type) {
92
+                    if (in_array($field, $includeIn) &&
83 93
                 !$page->AutomateableFields->find('DataField', $field) &&
84 94
                 AutomatedLink::isFieldParsable($page, $field)
85 95
             ) $page->AutomateableFields->push(DataObject::create(array('DataField' => $field)));
96
+        }
86 97
 
87 98
         // Get data Pre-Automated Links creation
88 99
         $withLinks = $this->getPageDOM($page);
89
-        if (!$withLinks) return false;
100
+        if (!$withLinks) {
101
+            return false;
102
+        }
90 103
 
91 104
         $links = $withLinks->getElementsByTagName('a');
92 105
 
@@ -96,10 +109,11 @@  discard block
 block discarded – undo
96 109
 
97 110
         // List all automated links that were created in this $page
98 111
         $linksUsed = array();
99
-        foreach ($this->Links as $autolink)
100
-            foreach ($links as $link) {
112
+        foreach ($this->Links as $autolink) {
113
+                    foreach ($links as $link) {
101 114
                 if ($link->getAttribute('data-id') == $autolink->ID) {
102 115
                     $linksUsed[$autolink->ID] = $autolink->Phrase;
116
+        }
103 117
                     $page->OriginalLinkCount--;
104 118
                     $page->LinkCount++;
105 119
                 }
@@ -107,7 +121,9 @@  discard block
 block discarded – undo
107 121
 
108 122
         $page->Links = implode(', ', $linksUsed);
109 123
 
110
-        if ($page->LinkCount < 1) return false;
124
+        if ($page->LinkCount < 1) {
125
+            return false;
126
+        }
111 127
 
112 128
         return $page;
113 129
     }
@@ -122,8 +138,12 @@  discard block
 block discarded – undo
122 138
      */
123 139
     private function getPageDOM(SiteTree $page) {
124 140
         $controllerClass = $page->class.'_Controller';
125
-        if (!class_exists($controllerClass))  $controllerClass = $page->class.'Controller';
126
-        if (!class_exists($controllerClass)) return false;
141
+        if (!class_exists($controllerClass)) {
142
+            $controllerClass = $page->class.'Controller';
143
+        }
144
+        if (!class_exists($controllerClass)) {
145
+            return false;
146
+        }
127 147
 
128 148
         $controller = $controllerClass::create($page);
129 149
         $controller->invokeWithExtensions('addAutomatedLinks');
@@ -154,9 +174,10 @@  discard block
 block discarded – undo
154 174
      * @return Boolean
155 175
      */
156 176
     private function checkForPossibleLinks(SiteTree $page, array $includeIn) {
157
-        foreach ($this->Links as $link)
158
-            foreach ($includeIn as $possibleField)
177
+        foreach ($this->Links as $link) {
178
+                    foreach ($includeIn as $possibleField)
159 179
                 if (isset($page->$possibleField) && preg_match("/\b{$link->Phrase}\b/i", $page->$possibleField)) return true;
180
+        }
160 181
 
161 182
         return false;
162 183
     }
Please login to merge, or discard this patch.