Browse Source

First commit

Timothy J. Warren 2 years ago
commit
86d649e9e8
51 changed files with 4591 additions and 0 deletions
  1. 20
    0
      .editorconfig
  2. 29
    0
      .gitignore
  3. 3
    0
      README.md
  4. 330
    0
      RoboFile.php
  5. 28
    0
      build/CodeIgniter/Docs/Files/ClosingFileAndLocationCommentStandard.xml
  6. 7
    0
      build/CodeIgniter/Docs/Files/Utf8EncodingAndByteOrderMarkStandard.xml
  7. 31
    0
      build/CodeIgniter/Docs/NamingConventions/ConstructorNameStandard.xml
  8. 21
    0
      build/CodeIgniter/Docs/NamingConventions/ValidClassNameStandard.xml
  9. 21
    0
      build/CodeIgniter/Docs/NamingConventions/ValidFileNameStandard.xml
  10. 27
    0
      build/CodeIgniter/Docs/NamingConventions/ValidMethodNameStandard.xml
  11. 31
    0
      build/CodeIgniter/Docs/NamingConventions/ValidVariableNameStandard.xml
  12. 40
    0
      build/CodeIgniter/Docs/Operators/StrictComparisonOperatorStandard.xml
  13. 28
    0
      build/CodeIgniter/Docs/Strings/DoubleQuoteUsageStandard.xml
  14. 187
    0
      build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php
  15. 98
    0
      build/CodeIgniter/Sniffs/Files/ByteOrderMarkSniff.php
  16. 222
    0
      build/CodeIgniter/Sniffs/Files/Utf8EncodingSniff.php
  17. 81
    0
      build/CodeIgniter/Sniffs/Operators/LogicalOperatorAndSniff.php
  18. 81
    0
      build/CodeIgniter/Sniffs/Operators/StrictComparisonOperatorSniff.php
  19. 84
    0
      build/CodeIgniter/Sniffs/Operators/UppercaseLogicalOperatorOrSniff.php
  20. 464
    0
      build/CodeIgniter/Sniffs/Strings/DoubleQuoteUsageSniff.php
  21. 87
    0
      build/CodeIgniter/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php
  22. 95
    0
      build/CodeIgniter/Sniffs/WhiteSpace/DisallowWitheSpaceAroundPhpTagsSniff.php
  23. 82
    0
      build/CodeIgniter/Sniffs/WhiteSpace/ElseOnNewLineSniff.php
  24. 75
    0
      build/CodeIgniter/Sniffs/WhiteSpace/LogicalNotSpacingSniff.php
  25. 104
    0
      build/CodeIgniter/UnusedSniffs/Files/AbstractClosingCommentSniff.php
  26. 109
    0
      build/CodeIgniter/UnusedSniffs/Files/ClosingFileCommentSniff.php
  27. 182
    0
      build/CodeIgniter/UnusedSniffs/Files/ClosingLocationCommentSniff.php
  28. 142
    0
      build/CodeIgniter/UnusedSniffs/NamingConventions/ConstructorNameSniff.php
  29. 84
    0
      build/CodeIgniter/UnusedSniffs/NamingConventions/ValidClassNameSniff.php
  30. 84
    0
      build/CodeIgniter/UnusedSniffs/NamingConventions/ValidFileNameSniff.php
  31. 161
    0
      build/CodeIgniter/UnusedSniffs/NamingConventions/ValidMethodNameSniff.php
  32. 562
    0
      build/CodeIgniter/UnusedSniffs/NamingConventions/ValidVariableNameSniff.php
  33. 47
    0
      build/CodeIgniter/ruleset.xml
  34. 13
    0
      build/header_comment.txt
  35. 84
    0
      build/phpcs.xml
  36. 128
    0
      build/phpdox.xml
  37. 26
    0
      build/phpunit.xml
  38. 70
    0
      build/update_header_comments.php
  39. 37
    0
      composer.json
  40. 15
    0
      phpdoc.dist.xml
  41. 18
    0
      phpunit.xml
  42. 208
    0
      src/CachePool.php
  43. 23
    0
      src/Driver/Driver.php
  44. 121
    0
      src/Driver/DriverCacheItem.php
  45. 42
    0
      src/Driver/DriverInterface.php
  46. 23
    0
      src/Driver/RedisDriver.php
  47. 23
    0
      src/Driver/SQLDriver.php
  48. 25
    0
      src/Exception/CacheException.php
  49. 28
    0
      src/Exception/InvalidArgumentException.php
  50. 56
    0
      src/ItemCollection.php
  51. 4
    0
      tests/bootstrap.php

+ 20
- 0
.editorconfig View File

@@ -0,0 +1,20 @@
1
+# EditorConfig is awesome: http://EditorConfig.org
2
+
3
+# top-most EditorConfig file
4
+root = true
5
+
6
+# Unix-style newlines with a newline ending every file
7
+[*]
8
+end_of_line = lf
9
+insert_final_newline = false
10
+charset = utf-8
11
+indent_style = tab
12
+trim_trailing_whitespace = true
13
+
14
+[*.{cpp,c,h,hpp,cxx}]
15
+insert_final_newline = true
16
+
17
+# Yaml files
18
+[*.{yml,yaml}]
19
+indent_style = space
20
+indent_size = 4

+ 29
- 0
.gitignore View File

@@ -0,0 +1,29 @@
1
+.codelite
2
+.phing_targets
3
+.sonar/
4
+*.phprj
5
+*.workspace
6
+vendor
7
+**/cache/**
8
+**/logs/**
9
+**/coverage/**
10
+**/docs/**
11
+**/node_modules/**
12
+public/images/*
13
+composer.lock
14
+*.sqlite
15
+*.db
16
+*.sqlite3
17
+docs/*
18
+tests/test_data/sessions/*
19
+cache.properties
20
+build/**
21
+!build/*.txt
22
+!build/*.xml
23
+!build/*.php
24
+app/config/*.toml
25
+!app/config/*.toml.example
26
+phinx.yml
27
+.idea/
28
+Caddyfile
29
+build/humbuglog.txt

+ 3
- 0
README.md View File

@@ -0,0 +1,3 @@
1
+# Banker
2
+
3
+A Caching library implementing the PSR-6 interface for several common cache backends

+ 330
- 0
RoboFile.php View File

@@ -0,0 +1,330 @@
1
+<?php
2
+if ( ! function_exists('glob_recursive'))
3
+{
4
+	// Does not support flag GLOB_BRACE
5
+	function glob_recursive($pattern, $flags = 0)
6
+	{
7
+		$files = glob($pattern, $flags);
8
+
9
+		foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
10
+		{
11
+			$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
12
+		}
13
+
14
+		return $files;
15
+	}
16
+}
17
+
18
+/**
19
+ * This is project's console commands configuration for Robo task runner.
20
+ *
21
+ * @see http://robo.li/
22
+ */
23
+class RoboFile extends \Robo\Tasks {
24
+
25
+	/**
26
+	 * Directories used by analysis tools
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected $taskDirs = [
31
+		'build/logs',
32
+		'build/pdepend',
33
+		'build/phpdox',
34
+	];
35
+
36
+	/**
37
+	 * Directories to remove with the clean task
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $cleanDirs = [
42
+		'coverage',
43
+		'docs',
44
+		'phpdoc',
45
+		'build/logs',
46
+		'build/phpdox',
47
+		'build/pdepend'
48
+	];
49
+
50
+
51
+	/**
52
+	 * Do static analysis tasks
53
+	 */
54
+	public function analyze()
55
+	{
56
+		$this->prepare();
57
+		$this->lint();
58
+		$this->phploc(TRUE);
59
+		$this->phpcs(TRUE);
60
+		$this->dependencyReport();
61
+		$this->phpcpdReport();
62
+	}
63
+
64
+	/**
65
+	 * Run all tests, generate coverage, generate docs, generate code statistics
66
+	 */
67
+	public function build()
68
+	{
69
+		$this->analyze();
70
+		$this->coverage();
71
+		$this->docs();
72
+	}
73
+
74
+	/**
75
+	 * Cleanup temporary files
76
+	 */
77
+	public function clean()
78
+	{
79
+		$cleanFiles = [
80
+			'build/humbug.json',
81
+			'build/humbug-log.txt',
82
+		];
83
+		array_map(function ($file) {
84
+			@unlink($file);
85
+		}, $cleanFiles);
86
+
87
+		// So the task doesn't complain,
88
+		// make any 'missing' dirs to cleanup
89
+		array_map(function ($dir) {
90
+			if ( ! is_dir($dir))
91
+			{
92
+				`mkdir -p {$dir}`;
93
+			}
94
+		}, $this->cleanDirs);
95
+
96
+		$this->_cleanDir($this->cleanDirs);
97
+		$this->_deleteDir($this->cleanDirs);
98
+	}
99
+
100
+	/**
101
+	 * Run unit tests and generate coverage reports
102
+	 */
103
+	public function coverage()
104
+	{
105
+		$this->taskPhpUnit()
106
+			->configFile('build/phpunit.xml')
107
+			->printed(true)
108
+			->run();
109
+	}
110
+
111
+	/**
112
+	 * Generate documentation with phpdox
113
+	 */
114
+	public function docs()
115
+	{
116
+		$cmd_parts = [
117
+			'cd build',
118
+			'../vendor/bin/phpdox',
119
+			'cd ..'
120
+		];
121
+		$this->_run($cmd_parts, ' && ');
122
+	}
123
+
124
+	/**
125
+	 * Verify that source files are valid
126
+	 */
127
+	public function lint()
128
+	{
129
+		$files = $this->getAllSourceFiles();
130
+
131
+		$chunks = array_chunk($files, 6);
132
+
133
+		foreach($chunks as $chunk)
134
+		{
135
+			$this->parallelLint($chunk);
136
+		}
137
+	}
138
+
139
+
140
+	/**
141
+	 * Run mutation tests with humbug
142
+	 *
143
+	 * @param bool $stats - if true, generates stats rather than running mutation tests
144
+	 */
145
+	public function mutate($stats = FALSE)
146
+	{
147
+		$test_parts = [
148
+			'vendor/bin/humbug'
149
+		];
150
+
151
+		$stat_parts = [
152
+			'vendor/bin/humbug',
153
+			'--skip-killed=yes',
154
+			'-v',
155
+			'./build/humbug.json'
156
+		];
157
+
158
+		$cmd_parts = ($stats) ? $stat_parts : $test_parts;
159
+		$this->_run($cmd_parts);
160
+	}
161
+
162
+	/**
163
+	 * Run the phpcs tool
164
+	 *
165
+	 * @param bool $report - if true, generates reports instead of direct output
166
+	 */
167
+	public function phpcs($report = FALSE)
168
+	{
169
+		$report_cmd_parts = [
170
+			'vendor/bin/phpcs',
171
+			'--standard=./build/phpcs.xml',
172
+			'--report-checkstyle=./build/logs/phpcs.xml',
173
+		];
174
+
175
+		$normal_cmd_parts = [
176
+			'vendor/bin/phpcs',
177
+			'--standard=./build/phpcs.xml',
178
+		];
179
+
180
+		$cmd_parts = ($report) ? $report_cmd_parts : $normal_cmd_parts;
181
+
182
+		$this->_run($cmd_parts);
183
+	}
184
+
185
+	/**
186
+	 * Run the phploc tool
187
+	 *
188
+	 * @param bool $report - if true, generates reports instead of direct output
189
+	 */
190
+	public function phploc($report = FALSE)
191
+	{
192
+		// Command for generating reports
193
+		$report_cmd_parts = [
194
+			'vendor/bin/phploc',
195
+			'--count-tests',
196
+			'--log-csv=build/logs/phploc.csv',
197
+			'--log-xml=build/logs/phploc.xml',
198
+			'src',
199
+			'tests'
200
+		];
201
+
202
+		// Command for generating direct output
203
+		$normal_cmd_parts = [
204
+			'vendor/bin/phploc',
205
+			'--count-tests',
206
+			'src',
207
+			'tests'
208
+		];
209
+
210
+		$cmd_parts = ($report) ? $report_cmd_parts : $normal_cmd_parts;
211
+
212
+		$this->_run($cmd_parts);
213
+	}
214
+
215
+	/**
216
+	 * Create temporary directories
217
+	 */
218
+	public function prepare()
219
+	{
220
+		array_map([$this, '_mkdir'], $this->taskDirs);
221
+	}
222
+
223
+	/**
224
+	 * Lint php files and run unit tests
225
+	 */
226
+	public function test()
227
+	{
228
+		$this->lint();
229
+		$this->taskPHPUnit()
230
+			->configFile('phpunit.xml')
231
+			->printed(true)
232
+			->run();
233
+	}
234
+
235
+	/**
236
+	 * Watches for file updates, and automatically runs appropriate actions
237
+	 */
238
+	public function watch()
239
+	{
240
+		$this->taskWatch()
241
+			->monitor('composer.json', function() {
242
+				$this->taskComposerUpdate()->run();
243
+			})
244
+			->monitor('src', function () {
245
+				$this->taskExec('test')->run();
246
+			})
247
+			->monitor('tests', function () {
248
+				$this->taskExec('test')->run();
249
+			})
250
+			->run();
251
+	}
252
+
253
+	/**
254
+	 * Create pdepend reports
255
+	 */
256
+	protected function dependencyReport()
257
+	{
258
+		$cmd_parts = [
259
+			'vendor/bin/pdepend',
260
+			'--jdepend-xml=build/logs/jdepend.xml',
261
+			'--jdepend-chart=build/pdepend/dependencies.svg',
262
+			'--overview-pyramid=build/pdepend/overview-pyramid.svg',
263
+			'src'
264
+		];
265
+		$this->_run($cmd_parts);
266
+	}
267
+
268
+	/**
269
+	 * Get the total list of source files, including tests
270
+	 *
271
+	 * @return array
272
+	 */
273
+	protected function getAllSourceFiles()
274
+	{
275
+		$files = array_merge(
276
+			glob_recursive('build/*.php'),
277
+			glob_recursive('src/*.php'),
278
+			glob_recursive('tests/*.php'),
279
+			glob('*.php')
280
+		);
281
+
282
+		sort($files);
283
+
284
+		return $files;
285
+	}
286
+
287
+	/**
288
+	 * Run php's linter in one parallel task for the passed chunk
289
+	 *
290
+	 * @param array $chunk
291
+	 */
292
+	protected function parallelLint(array $chunk)
293
+	{
294
+		$task = $this->taskParallelExec()
295
+			->timeout(5)
296
+			->printed(FALSE);
297
+
298
+		foreach($chunk as $file)
299
+		{
300
+			$task = $task->process("php -l {$file}");
301
+		}
302
+
303
+		$task->run();
304
+	}
305
+
306
+	/**
307
+	 * Generate copy paste detector report
308
+	 */
309
+	protected function phpcpdReport()
310
+	{
311
+		$cmd_parts = [
312
+			'vendor/bin/phpcpd',
313
+			'--log-pmd build/logs/pmd-cpd.xml',
314
+			'src'
315
+		];
316
+		$this->_run($cmd_parts);
317
+	}
318
+
319
+	/**
320
+	 * Shortcut for joining an array of command arguments
321
+	 * and then running it
322
+	 *
323
+	 * @param array $cmd_parts - command arguments
324
+	 * @param string $join_on - what to join the command arguments with
325
+	 */
326
+	protected function _run(array $cmd_parts, $join_on = ' ')
327
+	{
328
+		$this->taskExec(implode($join_on, $cmd_parts))->run();
329
+	}
330
+}

+ 28
- 0
build/CodeIgniter/Docs/Files/ClosingFileAndLocationCommentStandard.xml View File

@@ -0,0 +1,28 @@
1
+<documentation title="Closing comments instead of PHP closing tag">
2
+    <standard>
3
+    <![CDATA[
4
+    The PHP closing tag on a PHP document ?> is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files should OMIT the closing PHP tag, and instead use a comment block to mark the end of file and it's location relative to the application root. This allows you to still identify a file as being complete and not truncated.
5
+    ]]>
6
+    </standard>
7
+    <code_comparison>
8
+        <code title="Examples of valid closing comments">
9
+        <![CDATA[
10
+<?php
11
+
12
+  echo "Here's my code!";
13
+
14
+/* End of file myfile.php */
15
+/* Location: ./system/modules/mymodule/myfile.php */ 
16
+        ]]>
17
+        </code>
18
+        <code title="Examples of invalid closing comments">
19
+        <![CDATA[
20
+<?php
21
+
22
+  echo "Here's my code!";
23
+
24
+?> 
25
+        ]]>
26
+        </code>
27
+    </code_comparison>
28
+</documentation>

+ 7
- 0
build/CodeIgniter/Docs/Files/Utf8EncodingAndByteOrderMarkStandard.xml View File

@@ -0,0 +1,7 @@
1
+<documentation title="Unicode (UTF-8) encoding without BOM">
2
+    <standard>
3
+    <![CDATA[
4
+    Files should be saved with Unicode (UTF-8) encoding. The BOM should not be used. Unlike UTF-16 and UTF-32, there's no byte order to indicate in a UTF-8 encoded file, and the BOM can have a negative side effect in PHP of sending output, preventing the application from being able to set its own headers. Unix line endings should be used (LF).
5
+    ]]>
6
+    </standard>
7
+</documentation>

+ 31
- 0
build/CodeIgniter/Docs/NamingConventions/ConstructorNameStandard.xml View File

@@ -0,0 +1,31 @@
1
+<documentation title="Constructor Names">
2
+    <standard>
3
+    <![CDATA[
4
+    Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names.
5
+    ]]>
6
+    </standard>
7
+    <code_comparison>
8
+        <code title="Examples of valid constructor name">
9
+        <![CDATA[
10
+class Super_class
11
+{
12
+  function Super_class()
13
+  {
14
+    echo 'Some code here !';
15
+  }
16
+}
17
+        ]]>
18
+        </code>
19
+        <code title="Examples of invalid constructor name">
20
+        <![CDATA[
21
+class Super_class
22
+{
23
+  function __constructor()
24
+  {
25
+    echo 'Some code here !';
26
+  }
27
+}
28
+        ]]>
29
+        </code>
30
+    </code_comparison>
31
+</documentation>

+ 21
- 0
build/CodeIgniter/Docs/NamingConventions/ValidClassNameStandard.xml View File

@@ -0,0 +1,21 @@
1
+<documentation title="Class names">
2
+    <standard>
3
+    <![CDATA[
4
+    Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names.
5
+    ]]>
6
+    </standard>
7
+    <code_comparison>
8
+        <code title="Examples of valid class names">
9
+        <![CDATA[
10
+class Super_class
11
+        ]]>
12
+        </code>
13
+        <code title="Examples of invalid class names">
14
+        <![CDATA[
15
+class SuperClass // words not separated with underscores and words next to the first one start with an upper case
16
+class superclass // words not separated with underscores
17
+class Super_Class // words next to the first one start with an upper case
18
+        ]]>
19
+        </code>
20
+    </code_comparison>
21
+</documentation>

+ 21
- 0
build/CodeIgniter/Docs/NamingConventions/ValidFileNameStandard.xml View File

@@ -0,0 +1,21 @@
1
+<documentation title="File names">
2
+    <standard>
3
+    <![CDATA[
4
+    To be able to find which class is contained in a file, file names should be case-insensitively equal to class names. Some operating systems and tools are case-insensitive, though other are. So, file names should be in lower case to avoid any trouble.
5
+    ]]>
6
+    </standard>
7
+    <code_comparison>
8
+        <code title="Examples of valid file names">
9
+        <![CDATA[
10
+super_class.php
11
+        ]]>
12
+        </code>
13
+        <code title="Examples of invalid file names">
14
+        <![CDATA[
15
+superclass.php // words not separated with underscores
16
+SuperClass.php // not in lower case and words not separated with underscores
17
+Super_class.php // not in lower case
18
+        ]]>
19
+        </code>
20
+    </code_comparison>
21
+</documentation>

+ 27
- 0
build/CodeIgniter/Docs/NamingConventions/ValidMethodNameStandard.xml View File

@@ -0,0 +1,27 @@
1
+<documentation title="Function and Method Names">
2
+    <standard>
3
+    <![CDATA[
4
+    Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names.
5
+    Methods and variables that are only accessed internally by your class, such as utility and helper functions that your public methods use for code abstraction, should be prefixed with an underscore.
6
+    ]]>
7
+    </standard>
8
+    <code_comparison>
9
+        <code title="Examples of valid method names">
10
+        <![CDATA[
11
+function get_file_properties() // descriptive, underscore separator, and all lowercase letters
12
+private function _get_file_properties()
13
+        ]]>
14
+        </code>
15
+        <code title="Examples of invalid method names">
16
+        <![CDATA[
17
+function fileproperties() // not descriptive and needs underscore separator
18
+function fileProperties() // not descriptive and uses CamelCase
19
+function getfileproperties() // Better! But still missing underscore separator
20
+function getFileProperties() // uses CamelCase
21
+function get_the_file_properties_from_the_file() // wordy
22
+private function get_the_file_properties() // not prefixed with an underscor, though private
23
+function _get_the_file_properties() // prefixed with an underscor, though public
24
+        ]]>
25
+        </code>
26
+    </code_comparison>
27
+</documentation>

+ 31
- 0
build/CodeIgniter/Docs/NamingConventions/ValidVariableNameStandard.xml View File

@@ -0,0 +1,31 @@
1
+<documentation title="Variable names">
2
+    <standard>
3
+    <![CDATA[
4
+    Namely, variables should contain only lowercase letters, use underscore separators, and be reasonably named to indicate their purpose and contents. Very short, non-word variables should only be used as iterators in for() loops.
5
+    Methods and variables that are only accessed internally by your class, such as utility and helper functions that your public methods use for code abstraction, should be prefixed with an underscore.
6
+    ]]>
7
+    </standard>
8
+    <code_comparison>
9
+        <code title="Examples of valid variable names">
10
+        <![CDATA[
11
+for ($j = 0; $j < 10; $j++)
12
+$str
13
+$buffer
14
+$group_id
15
+$last_city
16
+private $_internal_data;
17
+        ]]>
18
+        </code>
19
+        <code title="Examples of invalid variable names">
20
+        <![CDATA[
21
+$j = 'foo'; // single letter variables should only be used in for() loops
22
+$Str // contains uppercase letters
23
+$bufferedText // uses CamelCasing, and could be shortened without losing semantic meaning
24
+$groupid // multiple words, needs underscore separator
25
+$name_of_last_city_used // too long
26
+private $internal_data; // not prefixed with an underscor, though private
27
+$_public_attribute; // prefixed with an underscor, though public
28
+        ]]>
29
+        </code>
30
+    </code_comparison>
31
+</documentation>

+ 40
- 0
build/CodeIgniter/Docs/Operators/StrictComparisonOperatorStandard.xml View File

@@ -0,0 +1,40 @@
1
+<documentation title="Strict comparison operators">
2
+    <standard>
3
+    <![CDATA[
4
+    Some PHP functions return FALSE on failure, but may also have a valid return value of "" or 0, which would evaluate to FALSE in loose comparisons. Be explicit by comparing the variable type when using these return values in conditionals to ensure the return value is indeed what you expect, and not a value that has an equivalent loose-type evaluation.
5
+    Use the same stringency in returning and checking your own variables. Use === and !== as necessary.
6
+    ]]>
7
+    </standard>
8
+    <code_comparison>
9
+        <code title="Valid strict comparison">
10
+        <![CDATA[
11
+if (strpos($str, 'foo') === FALSE) {
12
+  echo 'Do something.';
13
+}
14
+
15
+function build_string($str = "")
16
+{
17
+  if ($str === "") {
18
+    echo 'Buid string.';
19
+  }
20
+}
21
+        ]]>
22
+        </code>
23
+        <code title="Invalid loose comparison">
24
+        <![CDATA[
25
+// If 'foo' is at the beginning of the string, strpos will return a 0,
26
+// resulting in this conditional evaluating as TRUE
27
+if (strpos($str, 'foo') == FALSE) {
28
+  echo 'Do something.';
29
+}
30
+
31
+function build_string($str = "")
32
+{
33
+  if ($str == "") { // uh-oh! What if FALSE or the integer 0 is passed as an argument?
34
+    echo 'Buid string.';
35
+  }
36
+}
37
+        ]]>
38
+        </code>
39
+    </code_comparison>
40
+</documentation>

+ 28
- 0
build/CodeIgniter/Docs/Strings/DoubleQuoteUsageStandard.xml View File

@@ -0,0 +1,28 @@
1
+<documentation title="Double-quoted strings">
2
+    <standard>
3
+    <![CDATA[
4
+    Always use single quoted strings unless you need variables parsed, and in cases where you do need variables parsed, use braces to prevent greedy token parsing. You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.
5
+    ]]>
6
+    </standard>
7
+    <code_comparison>
8
+        <code title="Examples of invalid double-quoted strings">
9
+        <![CDATA[
10
+"My String" // no variable parsing, so no use for double quotes
11
+"My string $foo" // needs braces
12
+'SELECT foo FROM bar WHERE baz = \'bag\'' // ugly
13
+'\r\n' // it isn't wrong, but it won't be interpreted as a new line feed
14
+        ]]>
15
+        </code>
16
+        <code title="Examples of valid double-quoted strings">
17
+        <![CDATA[
18
+'My String'
19
+"My string {$foo}" // variables in strings may be enclosed with braces in 2 ways
20
+"My string ${foo}"
21
+"My string {$foo['bar']}" // variables in strings may be an array entry
22
+"My string {$foo->bar}" // variables in strings may be an object attribute
23
+"SELECT foo FROM bar WHERE baz = 'bag'"
24
+"\n" // not specified in Code Igniter coding standard, but it should be allowed
25
+        ]]>
26
+        </code>
27
+    </code_comparison>
28
+</documentation>

+ 187
- 0
build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php View File

@@ -0,0 +1,187 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Commenting_InlineCommentSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2011 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Commenting_InlineCommentSniff.
17
+ *
18
+ * Ensure the use of single line comments within code (i.e //)
19
+ * and blank lines between large comment blocks and code.
20
+ *
21
+ * @category  PHP
22
+ * @package   PHP_CodeSniffer
23
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
24
+ * @copyright 2011 Thomas Ernest
25
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
26
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
27
+ */
28
+namespace CodeIgniter\Sniffs\Commenting;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class InlineCommentSniff implements Sniff
34
+{
35
+    /**
36
+     * @var int Limit defining long comments.
37
+     * Long comments count $longCommentLimit or more lines.
38
+     */
39
+    public $longCommentLimit = 5;
40
+
41
+    /**
42
+     * Returns an array of tokens this test wants to listen for.
43
+     *
44
+     * @return array
45
+     */
46
+    public function register()
47
+    {
48
+        return array(
49
+            T_COMMENT
50
+        );
51
+    }//end register()
52
+
53
+    /**
54
+     * Processes this test, when one of its tokens is encountered.
55
+     *
56
+     * @param File $phpcsFile The current file being scanned.
57
+     * @param int                  $stackPtr  The position of the current token
58
+     *                                        in the stack passed in $tokens.
59
+     *
60
+     * @return void
61
+     */
62
+    public function process(File $phpcsFile, $stackPtr)
63
+    {
64
+        $tokens = $phpcsFile->getTokens();
65
+
66
+        // keep testing only if it's about the first comment of the block
67
+        $previousCommentPtr = $phpcsFile->findPrevious($tokens[$stackPtr]['code'], $stackPtr - 1);
68
+        if ($tokens[$previousCommentPtr]['line'] !== $tokens[$stackPtr]['line'] - 1) {
69
+            if (TRUE !== $this->_checkCommentStyle($phpcsFile, $stackPtr)) {
70
+                return;
71
+            }
72
+
73
+            $commentLines = $this->_getCommentBlock($phpcsFile, $stackPtr);
74
+
75
+            if (count($commentLines) >= $this->longCommentLimit) {
76
+                $this->_checkBlankLinesAroundLongComment($phpcsFile, $commentLines);
77
+            }
78
+        }
79
+    }//end process()
80
+
81
+
82
+    /**
83
+     * Add error to $phpcsFile, if comment pointed by $stackPtr doesn't start
84
+     * with '//'.
85
+     *
86
+     * @param File $phpcsFile The current file being scanned.
87
+     * @param int                  $stackPtr  The position of the current token
88
+     *                                        that has to be a comment.
89
+     *
90
+     * @return bool TRUE if the content of the token pointed by $stackPtr starts
91
+     *              with //, FALSE if an error was added to $phpcsFile.
92
+     */
93
+    private function _checkCommentStyle(File $phpcsFile, $stackPtr)
94
+    {
95
+        $tokens = $phpcsFile->getTokens();
96
+        if ($tokens[$stackPtr]['content']{0} === '#') {
97
+            $error  = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
98
+            $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
99
+            return FALSE;
100
+        } else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
101
+            || $tokens[$stackPtr]['content']{0} === '*'
102
+        ) {
103
+            $error  = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
104
+            $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
105
+            return FALSE;
106
+        } else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
107
+            $error  = 'Use single line or DocBlock comments within code';
108
+            $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
109
+            return FALSE;
110
+        }
111
+        return TRUE;
112
+    }//_checkCommentStyle()
113
+
114
+
115
+    /**
116
+     * Gather into an array all comment lines to which $stackPtr belongs.
117
+     *
118
+     * @param File $phpcsFile The current file being scanned.
119
+     * @param int                  $stackPtr  Pointer to the first comment line.
120
+     *
121
+     * @return type array Pointers to tokens making up the comment block.
122
+     */
123
+    private function _getCommentBlock(File $phpcsFile, $stackPtr)
124
+    {
125
+        $tokens = $phpcsFile->getTokens();
126
+        $commentLines = array($stackPtr);
127
+        $nextComment  = $stackPtr;
128
+        $lastLine     = $tokens[$stackPtr]['line'];
129
+
130
+        while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), null, false)) !== false) {
131
+            if (($tokens[$nextComment]['line'] - 1) !== $lastLine) {
132
+                // Not part of the block.
133
+                break;
134
+            }
135
+
136
+            $lastLine       = $tokens[$nextComment]['line'];
137
+            $commentLines[] = $nextComment;
138
+        }
139
+
140
+        return $commentLines;
141
+    }//_getCommentBlock()
142
+
143
+
144
+    /**
145
+     * Add errors to $phpcsFile, if $commentLines isn't enclosed with blank lines.
146
+     *
147
+     * @param File $phpcsFile    The current file being scanned.
148
+     * @param array                $commentLines Lines of the comment block being checked.
149
+     *
150
+     * @return bool TRUE if $commentLines is enclosed with at least a blank line
151
+     * before and after, FALSE otherwise.
152
+     */
153
+    private function _checkBlankLinesAroundLongComment(File $phpcsFile, array $commentLines)
154
+    {
155
+        $hasBlankLinesAround = TRUE;
156
+        $tokens = $phpcsFile->getTokens();
157
+
158
+        // check blank line before the long comment
159
+        $firstCommentPtr = reset($commentLines);
160
+        $firstPreviousSpacePtr = $firstCommentPtr - 1;
161
+        while (T_WHITESPACE === $tokens[$firstPreviousSpacePtr]['code'] && $firstPreviousSpacePtr > 0) {
162
+            $firstPreviousSpacePtr--;
163
+        }
164
+        if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1) {
165
+            $error  = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines.";
166
+            $phpcsFile->addError($error, $firstCommentPtr, 'LongCommentWithoutSpacing');
167
+            $hasBlankLinesAround = FALSE;
168
+        }
169
+
170
+        // check blank line after the long comment
171
+        $lastCommentPtr = end($commentLines);
172
+        $lastNextSpacePtr = $lastCommentPtr + 1;
173
+        while (T_WHITESPACE === $tokens[$lastNextSpacePtr]['code'] && $lastNextSpacePtr < count($tokens)) {
174
+            $lastNextSpacePtr++;
175
+        }
176
+        if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1) {
177
+            $error  = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines.";
178
+            $phpcsFile->addError($error, $lastCommentPtr, 'LongCommentWithoutSpacing');
179
+            $hasBlankLinesAround = FALSE;
180
+        }
181
+
182
+        return $hasBlankLinesAround;
183
+    }//end _checkBlanksAroundLongComment()
184
+
185
+}//end class
186
+
187
+?>

+ 98
- 0
build/CodeIgniter/Sniffs/Files/ByteOrderMarkSniff.php View File

@@ -0,0 +1,98 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Files_ByteOrderMarkSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Files_ByteOrderMarkSniff.
17
+ *
18
+ * Ensures that no BOM appears at the beginning of file.
19
+ *
20
+ * @category  PHP
21
+ * @package   PHP_CodeSniffer
22
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
23
+ * @copyright 2006 Thomas Ernest
24
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
26
+ */
27
+
28
+namespace CodeIgniter\Sniffs\Files;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class ByteOrderMarkSniff implements Sniff
34
+{
35
+    /**
36
+     * Returns an array of tokens this test wants to listen for.
37
+     *
38
+     * @return array
39
+     */
40
+    public function register()
41
+    {
42
+        return array( T_OPEN_TAG );
43
+    }//end register()
44
+
45
+    /**
46
+     * List of supported BOM definitions.
47
+     *
48
+     * Use encoding names as keys and hex BOM representations as values.
49
+     *
50
+     * @return array
51
+     */
52
+    protected function getBomDefinitions()
53
+    {
54
+        return array(
55
+            'UTF-8'       => 'efbbbf',
56
+            'UTF-16 (BE)' => 'feff',
57
+            'UTF-16 (LE)' => 'fffe',
58
+            'UTF-32 (BE)' => '0000feff',
59
+            'UTF-32 (LE)' => 'fffe0000'
60
+        );
61
+    }//end getBomDefinitions()
62
+
63
+    /**
64
+     * Process tokens.
65
+     *
66
+     * Actually, only proceed when we're at index 0, this should be the only case
67
+     * that will contain BOM. Then check if BOM definition matches what
68
+     * we've found as file's inline HTML. Inline HTML could be longer than just BOM
69
+     * so make sure you test as much as needed.
70
+     *
71
+     * @param File $phpcsFile The current file being scanned.
72
+     * @param int                  $stackPtr  The position of the current token
73
+     *                                        in the stack passed in $tokens.
74
+     *
75
+     * @return void
76
+     */
77
+    public function process(File $phpcsFile, $stackPtr )
78
+    {
79
+        // We are only interested if this is the first open tag.
80
+        if ($stackPtr !== 0) {
81
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
82
+                return;
83
+            }
84
+        }
85
+
86
+        $tokens = $phpcsFile->getTokens();
87
+        $fileStartString = $tokens[0]['content'];
88
+        foreach ($this->getBomDefinitions() as $bomName => $expectedBomHex) {
89
+            $bomByteLength = strlen($expectedBomHex) / 2;
90
+            $fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength));
91
+            if ($fileStartHex === $expectedBomHex) {
92
+                $error = "File contains a $bomName byte order mark (BOM).";
93
+                $phpcsFile->addError($error, $stackPtr);
94
+                break;
95
+            }
96
+        }
97
+    }//end process()
98
+}

+ 222
- 0
build/CodeIgniter/Sniffs/Files/Utf8EncodingSniff.php View File

@@ -0,0 +1,222 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Files_Utf8EncodingSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Files_Utf8EncodingSniff.
17
+ *
18
+ * Ensures that PHP files are encoded with Unicode (UTF-8) encoding.
19
+ *
20
+ * @category  PHP
21
+ * @package   PHP_CodeSniffer
22
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
23
+ * @copyright 2006 Thomas Ernest
24
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
26
+ */
27
+
28
+namespace CodeIgniter\Sniffs\Files;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class Utf8EncodingSniff implements Sniff
34
+{
35
+
36
+    /**
37
+     * Returns an array of tokens this test wants to listen for.
38
+     *
39
+     * @return array
40
+     */
41
+    public function register()
42
+    {
43
+        return array(
44
+            T_OPEN_TAG
45
+        );
46
+
47
+    }//end register()
48
+
49
+
50
+    /**
51
+     * Processes this test, when one of its tokens is encountered.
52
+     *
53
+     * @param File $phpcsFile The current file being scanned.
54
+     * @param int                  $stackPtr  The position of the current token
55
+     *                                        in the stack passed in $tokens.
56
+     *
57
+     * @return void
58
+     */
59
+    public function process(File $phpcsFile, $stackPtr)
60
+    {
61
+        // We are only interested if this is the first open tag.
62
+        if ($stackPtr !== 0) {
63
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
64
+                return;
65
+            }
66
+        }
67
+
68
+        $file_path = $phpcsFile->getFilename();
69
+        $file_name = basename($file_path);
70
+        $file_content = file_get_contents($file_path);
71
+        if (false === mb_check_encoding($file_content, 'UTF-8')) {
72
+            $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding.';
73
+            $phpcsFile->addError($error, 0);
74
+        }
75
+        if ( ! self::_checkUtf8W3c($file_content)) {
76
+            $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not successfully pass the W3C test.';
77
+            $phpcsFile->addError($error, 0);
78
+        }
79
+        if ( ! self::_checkUtf8Rfc3629($file_content)) {
80
+            $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not meet RFC3629 requirements.';
81
+            $phpcsFile->addError($error, 0);
82
+        }
83
+    }//end process()
84
+
85
+
86
+    /**
87
+     * Checks that the string $content contains only valid UTF-8 chars
88
+     * using W3C's method.
89
+     * Returns true if $content contains only UTF-8 chars, false otherwise.
90
+     *
91
+     * @param string $content String to check.
92
+     *
93
+     * @return bool true if $content contains only UTF-8 chars, false otherwise.
94
+     *
95
+     * @see http://w3.org/International/questions/qa-forms-utf-8.html
96
+     */
97
+    private static function _checkUtf8W3c($content)
98
+    {
99
+        $content_chunks=self::mb_chunk_split($content, 4096, '');
100
+    	foreach($content_chunks as $content_chunk)
101
+		{
102
+			$preg_result= preg_match(
103
+            '%^(?:
104
+                  [\x09\x0A\x0D\x20-\x7E]            # ASCII
105
+                | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
106
+                |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
107
+                | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
108
+                |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
109
+                |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
110
+                | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
111
+                |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
112
+            )*$%xs',
113
+            $content_chunk
114
+			);
115
+			if($preg_result!==1)
116
+			{
117
+				return false;
118
+			}
119
+
120
+		}
121
+		return true;
122
+    }//end _checkUtf8W3c()
123
+
124
+    /**
125
+     * Checks that the string $content contains only valid UTF-8 chars
126
+     * using the method described in RFC 3629.
127
+     * Returns true if $content contains only UTF-8 chars, false otherwise.
128
+     *
129
+     * @param string $content String to check.
130
+     *
131
+     * @return bool true if $content contains only UTF-8 chars, false otherwise.
132
+     *
133
+     * @see http://www.php.net/manual/en/function.mb-detect-encoding.php#85294
134
+     */
135
+    private static function _checkUtf8Rfc3629($content)
136
+    {
137
+        $len = strlen($content);
138
+        for ($i = 0; $i < $len; $i++) {
139
+            $c = ord($content[$i]);
140
+            if ($c > 128) {
141
+                if (($c >= 254)) {
142
+                    return false;
143
+                } elseif ($c >= 252) {
144
+                    $bits=6;
145
+                } elseif ($c >= 248) {
146
+                    $bits=5;
147
+                } elseif ($c >= 240) {
148
+                    $bytes = 4;
149
+                } elseif ($c >= 224) {
150
+                    $bytes = 3;
151
+                } elseif ($c >= 192) {
152
+                    $bytes = 2;
153
+                } else {
154
+                    return false;
155
+                } if (($i + $bytes) > $len) {
156
+                    return false;
157
+                } while ($bytes > 1) {
158
+                    $i++;
159
+                    $b = ord($content[$i]);
160
+                    if ($b < 128 || $b > 191) {
161
+                        return false;
162
+                    }
163
+                    $bytes--;
164
+                }
165
+            }
166
+        }
167
+        return true;
168
+    }//_checkUtf8Rfc3629()
169
+
170
+	 /**
171
+     * Splits a string to chunks of given size
172
+	 * This helps to avoid segmentation fault errors when large text is given
173
+     * Returns array of strings after splitting
174
+     *
175
+     * @param string $str String to split.
176
+	 * @param int $len number of characters per chunk
177
+     *
178
+     * @return array string array after splitting
179
+     *
180
+     * @see http://php.net/manual/en/function.chunk-split.php
181
+     */
182
+	private static function mb_chunk_split($str, $len, $glue)
183
+	{
184
+		if (empty($str)) return false;
185
+		$array = self::mbStringToArray ($str);
186
+		$n = -1;
187
+		$new = Array();
188
+		foreach ($array as $char) {
189
+			$n++;
190
+			if ($n < $len) $new []= $char;
191
+			elseif ($n == $len) {
192
+				$new []= $glue . $char;
193
+				$n = 0;
194
+			}
195
+		}
196
+		return $new;
197
+	}//mb_chunk_split
198
+	/**
199
+     * Supporting function for mb_chunk_split
200
+     *
201
+     * @param string $str
202
+	 *
203
+     * @return array
204
+     *
205
+     * @see http://php.net/manual/en/function.chunk-split.php
206
+     */
207
+	private static function mbStringToArray ($str)
208
+	{
209
+		if (empty($str)) return false;
210
+		$len = mb_strlen($str);
211
+		$array = array();
212
+		for ($i = 0; $i < $len; $i++) {
213
+			$array[] = mb_substr($str, $i, 1);
214
+		}
215
+		return $array;
216
+	}
217
+
218
+
219
+
220
+}//end class
221
+
222
+?>

+ 81
- 0
build/CodeIgniter/Sniffs/Operators/LogicalOperatorAndSniff.php View File

@@ -0,0 +1,81 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Operators_LogicalOperatorAndSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Operators_LogicalOperatorAndSniff.
17
+ *
18
+ * Ensures that the logical operator 'AND' is in upper case and suggest the use of its symbolic equivalent.
19
+ *
20
+ * @category  PHP
21
+ * @package   PHP_CodeSniffer
22
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
23
+ * @copyright 2006 Thomas Ernest
24
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
26
+ */
27
+
28
+namespace CodeIgniter\Sniffs\Operators;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class LogicalOperatorAndSniff implements Sniff
34
+{
35
+	/**
36
+     * Returns an array of tokens this test wants to listen for: symbolic and literal operators and.
37
+     *
38
+     * @return array
39
+     */
40
+    public function register()
41
+    {
42
+        return array(
43
+            T_LOGICAL_AND,
44
+        );
45
+
46
+    }//end register()
47
+
48
+
49
+    /**
50
+     * Processes this test, when one of its tokens is encountered.
51
+     *
52
+     * @param File $phpcsFile The current file being scanned.
53
+     * @param int                  $stackPtr  The position of the current token
54
+     *                                        in the stack passed in $tokens.
55
+     *
56
+     * @return void
57
+     */
58
+    public function process(File $phpcsFile, $stackPtr)
59
+    {
60
+        $tokens = $phpcsFile->getTokens();
61
+
62
+        $operator_token = $tokens[$stackPtr];
63
+        $operator_string = $operator_token['content'];
64
+        $operator_code = $operator_token['code'];
65
+
66
+        if ($operator_string !== strtoupper($operator_string)) {
67
+            $error_message = 'Logical operator should be in upper case;'
68
+                . ' use "' . strtoupper($operator_string)
69
+                . '" instead of "' . $operator_string . '"';
70
+            $phpcsFile->addError($error_message, $stackPtr, 'LowercaseLogicalOperator');
71
+        }
72
+
73
+        $warning_message = 'The symbolic form "&&" is preferred over the literal form "AND"';
74
+        $phpcsFile->addWarning($warning_message, $stackPtr, 'UseOfLiteralAndOperator');
75
+
76
+    }//end process()
77
+
78
+
79
+}//end class
80
+
81
+?>

+ 81
- 0
build/CodeIgniter/Sniffs/Operators/StrictComparisonOperatorSniff.php View File

@@ -0,0 +1,81 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Operators_StrictComparisonOperatorSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Operators_StrictComparisonOperatorSniff.
17
+ *
18
+ * Ensures that only strict comparison operators are used instead of
19
+ * equal and not equal operators.
20
+ *
21
+ * @category  PHP
22
+ * @package   PHP_CodeSniffer
23
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
24
+ * @copyright 2006 Thomas Ernest
25
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
26
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
27
+ */
28
+
29
+namespace CodeIgniter\Sniffs\Operators;
30
+
31
+use PHP_CodeSniffer\Sniffs\Sniff;
32
+use PHP_CodeSniffer\Files\File;
33
+
34
+class StrictComparisonOperatorSniff implements Sniff
35
+{
36
+    private static $_replacements = array(
37
+        T_IS_EQUAL     => '===',
38
+        T_IS_NOT_EQUAL => '!==',
39
+    );
40
+
41
+    /**
42
+     * Returns an array of tokens this test wants to listen for.
43
+     *
44
+     * @return array
45
+     */
46
+    public function register()
47
+    {
48
+        return array(
49
+            T_IS_EQUAL,
50
+            T_IS_NOT_EQUAL,
51
+        );
52
+    }//end register()
53
+
54
+
55
+    /**
56
+     * Processes this test, when one of its tokens is encountered.
57
+     *
58
+     * @param File $phpcsFile The current file being scanned.
59
+     * @param int                  $stackPtr  The position of the current token
60
+     *                                        in the stack passed in $tokens.
61
+     *
62
+     * @return void
63
+     */
64
+    public function process(File $phpcsFile, $stackPtr)
65
+    {
66
+        $tokens = $phpcsFile->getTokens();
67
+
68
+        $operator_token = $tokens[$stackPtr];
69
+        $operator_string = $operator_token['content'];
70
+        $operator_code = $operator_token['code'];
71
+
72
+        $error_message = '"==" and "!=" are prohibited; use "'
73
+            . self::$_replacements[$operator_code] . '" instead of "'
74
+            . $operator_string . '".';
75
+        $phpcsFile->addError($error_message, $stackPtr, 'NonStrictComparisonUsed');
76
+    }//end process()
77
+
78
+
79
+}//end class
80
+
81
+?>

+ 84
- 0
build/CodeIgniter/Sniffs/Operators/UppercaseLogicalOperatorOrSniff.php View File

@@ -0,0 +1,84 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Operators_UppercaseLogicalOperatorOrSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Operators_UppercaseLogicalOperatorOrSniff.
17
+ *
18
+ * Ensures that the logical operator 'OR' is in upper cases and its symbolic equivalent.
19
+ *
20
+ * @category  PHP
21
+ * @package   PHP_CodeSniffer
22
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
23
+ * @copyright 2006 Thomas Ernest
24
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
26
+ */
27
+
28
+namespace CodeIgniter\Sniffs\Operators;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class UppercaseLogicalOperatorOrSniff implements Sniff
34
+{
35
+    /**
36
+     * Returns an array of tokens this test wants to listen for: literal and symbolic operators or.
37
+     *
38
+     * @return array
39
+     */
40
+    public function register()
41
+    {
42
+        return array(
43
+            T_BOOLEAN_OR,
44
+            T_LOGICAL_OR,
45
+        );
46
+
47
+    }//end register()
48
+
49
+
50
+    /**
51
+     * Processes this test, when one of its tokens is encountered.
52
+     *
53
+     * @param File $phpcsFile The current file being scanned.
54
+     * @param int                  $stackPtr  The position of the current token
55
+     *                                        in the stack passed in $tokens.
56
+     *
57
+     * @return void
58
+     */
59
+    public function process(File $phpcsFile, $stackPtr)
60
+    {
61
+        $tokens = $phpcsFile->getTokens();
62
+
63
+        $operator_token = $tokens[$stackPtr];
64
+        $operator_string = $operator_token['content'];
65
+        $operator_code = $operator_token['code'];
66
+
67
+        if ($operator_code == T_BOOLEAN_OR) {
68
+            $error_message = 'Logical operator "' . $operator_string
69
+                . '" is prohibited; use "OR" instead';
70
+            $phpcsFile->addError($error_message, $stackPtr, 'UseOf||InsteadOfOR');
71
+        }
72
+        // it is literal, if it is not symbolic
73
+        else if ($operator_string !== strtoupper($operator_string)) {
74
+            $error_message = 'Logical operator should be in upper case;'
75
+                . ' use "' . strtoupper($operator_string)
76
+                . '" instead of "' . $operator_string . '"';
77
+            $phpcsFile->addError($error_message, $stackPtr, 'UseOfLowercaseOr');
78
+        }
79
+    }//end process()
80
+
81
+
82
+}//end class
83
+
84
+?>

+ 464
- 0
build/CodeIgniter/Sniffs/Strings/DoubleQuoteUsageSniff.php View File

@@ -0,0 +1,464 @@
1
+<?php
2
+
3
+/**
4
+ * CodeIgniter_Sniffs_Strings_DoubleQuoteUsageSniff.
5
+ *
6
+ * PHP version 5
7
+ *
8
+ * @category  PHP
9
+ * @package   PHP_CodeSniffer
10
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
11
+ * @copyright 2011 Thomas Ernest
12
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
13
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
14
+ */
15
+
16
+namespace CodeIgniter\Sniffs\Strings;
17
+
18
+use PHP_CodeSniffer\Sniffs\Sniff;
19
+use PHP_CodeSniffer\Files\File;
20
+
21
+/**
22
+ * CodeIgniter_Sniffs_Strings_DoubleQuoteUsageSniff.
23
+ *
24
+ * Ensures that double-quoted strings are used only to parse variables,
25
+ * to avoid escape characters before single quotes or for chars that need
26
+ * to be interpreted like \r, \n or \t.
27
+ * If a double-quoted string contain both single and double quotes
28
+ * but no variable, then a warning is raised to encourage the use of
29
+ * single-quoted strings.
30
+ *
31
+ * @category  PHP
32
+ * @package   PHP_CodeSniffer
33
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
34
+ * @copyright 2011 Thomas Ernest
35
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
36
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
37
+ */
38
+class VariableUsageSniff implements Sniff
39
+{
40
+	/**
41
+	 * Returns an array of tokens this test wants to listen for.
42
+	 *
43
+	 * @return array
44
+	 */
45
+	public function register()
46
+	{
47
+		/*
48
+		return array(
49
+			T_DOUBLE_QUOTED_STRING,
50
+			T_CONSTANT_ENCAPSED_STRING,
51
+		);
52
+		*/
53
+		return array();
54
+	}//end register()
55
+
56
+
57
+	/**
58
+	 * Processes this test, when one of its tokens is encountered.
59
+	 *
60
+	 * @param File $phpcsFile The current file being scanned.
61
+	 * @param int                  $stackPtr  The position of the current token
62
+	 *                                        in the stack passed in $tokens.
63
+	 *
64
+	 * @return void
65
+	 */
66
+	public function process(File $phpcsFile, $stackPtr)
67
+	{
68
+		$tokens = $phpcsFile->getTokens();
69
+		$string = $tokens[$stackPtr]['content'];
70
+		// makes sure that it is about a double quote string,
71
+		// since variables are not parsed out of double quoted string
72
+		$openDblQtStr = substr($string, 0, 1);
73
+		if (0 === strcmp($openDblQtStr, '"')) {
74
+			$this->processDoubleQuotedString($phpcsFile, $stackPtr, $string);
75
+		} else if (0 === strcmp($openDblQtStr, "'")) {
76
+			$this->processSingleQuotedString($phpcsFile, $stackPtr, $string);
77
+		}
78
+	}//end process()
79
+
80
+
81
+	/**
82
+	 * Processes this test, when the token encountered is a double-quoted string.
83
+	 *
84
+	 * @param File $phpcsFile   The current file being scanned.
85
+	 * @param int                  $stackPtr    The position of the current token
86
+	 *                                          in the stack passed in $tokens.
87
+	 * @param string               $dblQtString The double-quoted string content,
88
+	 *                                          i.e. without quotes.
89
+	 *
90
+	 * @return void
91
+	 */
92
+	protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $dblQtString)
93
+	{
94
+		$variableFound = FALSE;
95
+		$strTokens = token_get_all('<?php '.$dblQtString);
96
+		$strPtr = 1; // skip php opening tag added by ourselves
97
+		$requireDblQuotes = FALSE;
98
+		while ($strPtr < count($strTokens)) {
99
+			$strToken = $strTokens[$strPtr];
100
+			if (is_array($strToken)) {
101
+				if (in_array($strToken[0], array(T_DOLLAR_OPEN_CURLY_BRACES, T_CURLY_OPEN))) {
102
+					$strPtr++;
103
+					try {
104
+						$this->_parseVariable($strTokens, $strPtr);
105
+					} catch (Exception $err) {
106
+						$error = 'There is no variable, object nor array between curly braces. Please use the escape char for $ or {.';
107
+						$phpcsFile->addError($error, $stackPtr);
108
+					}
109
+					$variableFound = TRUE;
110
+					if ('}' !== $strTokens[$strPtr]) {
111
+						$error = 'There is no matching closing curly brace.';
112
+						$phpcsFile->addError($error, $stackPtr);
113
+					}
114
+					// don't move forward, since it will be done in the main loop
115
+					// $strPtr++;
116
+				} else if (T_VARIABLE === $strToken[0]) {
117
+					$variableFound = TRUE;
118
+					$error = "Variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}";
119
+					$phpcsFile->addError($error, $stackPtr);
120
+				}
121
+			}
122
+			$strPtr++;
123
+		}
124
+		return $variableFound;
125
+	}//end processDoubleQuotedString()
126
+
127
+
128
+	/**
129
+	 * Processes this test, when the token encountered is a single-quoted string.
130
+	 *
131
+	 * @param File $phpcsFile   The current file being scanned.
132
+	 * @param int                  $stackPtr    The position of the current token
133
+	 *                                          in the stack passed in $tokens.
134
+	 * @param string               $sglQtString The single-quoted string content,
135
+	 *                                          i.e. without quotes.
136
+	 *
137
+	 * @return void
138
+	 */
139
+	protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $sglQtString)
140
+	{
141
+		$variableFound = FALSE;
142
+		$strTokens = token_get_all('<?php '.$sglQtString);
143
+		$strPtr = 1; // skip php opening tag added by ourselves
144
+		while ($strPtr < count($strTokens)) {
145
+			$strToken = $strTokens[$strPtr];
146
+			if (is_array($strToken)) {
147
+				if (T_VARIABLE === $strToken[0]) {
148
+					$error = "Variables like {$strToken[1]} should be in double-quoted strings only.";
149
+					$phpcsFile->addError($error, $stackPtr);
150
+				}
151
+			}
152
+			$strPtr++;
153
+		}
154
+		return $variableFound;
155
+	}//end processSingleQuotedString()
156
+
157
+	/**
158
+	 * Grammar rule to parse the use of a variable. Please notice that it
159
+	 * doesn't manage the leading $.
160
+	 *
161
+	 * _parseVariable ::= <variable>
162
+	 *     | <variable>_parseObjectAttribute()
163
+	 *     | <variable>_parseArrayIndexes()
164
+	 *
165
+	 * @exception Exception raised if $strTokens starting from $strPtr
166
+	 *                      doesn't matched the rule.
167
+	 *
168
+	 * @param array $strTokens Tokens to parse.
169
+	 * @param int   $strPtr    Pointer to the token where parsing starts.
170
+	 *
171
+	 * @return array The attribute name associated to index 'var', an array with
172
+	 * indexes 'obj' and 'attr' or an array with indexes 'arr' and 'idx'.
173
+	 */
174
+	private function _parseVariable ($strTokens, &$strPtr)
175
+	{
176
+		if ( ! in_array($strTokens[$strPtr][0], array(T_VARIABLE, T_STRING_VARNAME))) {
177
+			throw new Exception ('Expected variable name.');
178
+		}
179
+		$var = $strTokens[$strPtr][1];
180
+		$strPtr++;
181
+		$startStrPtr = $strPtr;
182
+		try {
183
+			$attr = $this->_parseObjectAttribute($strTokens, $strPtr);
184
+			return array ('obj' => $var, 'attr' => $attr);
185
+		} catch (Exception $err) {
186
+			if ($strPtr !== $startStrPtr) {
187
+				throw $err;
188
+			}
189
+		}
190
+		try {
191
+			$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
192
+			return array ('arr' => $var, 'idx' => $idx);
193
+		} catch (Exception $err) {
194
+			if ($strPtr !== $startStrPtr) {
195
+				throw $err;
196
+			}
197
+		}
198
+		return array ('var' => $var);
199
+	}//end _parseVariable()
200
+
201
+
202
+	/**
203
+	 * Grammar rule to parse the use of an object attribute.
204
+	 *
205
+	 * _parseObjectAttribute ::= -><attribute>
206
+	 *     | -><attribute>_parseObjectAttribute()
207
+	 *     | -><attribute>_parseArrayIndexes()
208
+	 *
209
+	 * @exception Exception raised if $strTokens starting from $strPtr
210
+	 *                      doesn't matched the rule.
211
+	 *
212
+	 * @param array $strTokens Tokens to parse.
213
+	 * @param int   $strPtr    Pointer to the token where parsing starts.
214
+	 *
215
+	 * @return mixed The attribute name as a string, an array with indexes
216
+	 * 'obj' and 'attr' or an array with indexes 'arr' and 'idx'.
217
+	 */
218
+	private function _parseObjectAttribute ($strTokens, &$strPtr)
219
+	{
220
+		if (T_OBJECT_OPERATOR !== $strTokens[$strPtr][0]) {
221
+			throw new Exception ('Expected ->.');
222
+		}
223
+		$strPtr++;
224
+		if (T_STRING !== $strTokens[$strPtr][0]) {
225
+			throw new Exception ('Expected an object attribute.');
226
+		}
227
+		$attr = $strTokens[$strPtr][1];
228
+		$strPtr++;
229
+		$startStrPtr = $strPtr;
230
+		try {
231
+			$sub_attr = $this->_parseObjectAttribute($strTokens, $strPtr);
232
+			return array ('obj' => $attr, 'attr' => $sub_attr);
233
+		} catch (Exception $err) {
234
+			if ($strPtr !== $startStrPtr) {
235
+				throw $err;
236
+			}
237
+		}
238
+		try {
239
+			$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
240
+			return array ('arr' => $attr, 'idx' => $idx);
241
+		} catch (Exception $err) {
242
+			if ($strPtr !== $startStrPtr) {
243
+				throw $err;
244
+			}
245
+		}
246
+		return $attr;
247
+	}//end _parseObjectAttribute()
248
+
249
+
250
+	/**
251
+	 * Grammar rule to parse the use of one or more array indexes.
252
+	 *
253
+	 * _parseArrayIndexes ::= _parseArrayIndex()+
254
+	 *
255
+	 * @exception Exception raised if $strTokens starting from $strPtr
256
+	 *                      doesn't matched the rule.
257
+	 *
258
+	 * @param array $strTokens Tokens to parse.
259
+	 * @param int   $strPtr    Pointer to the token where parsing starts.
260
+	 *
261
+	 * @return array Indexes in the same order as in the string.
262
+	 */
263
+	private function _parseArrayIndexes ($strTokens, &$strPtr)
264
+	{
265
+		$indexes = array($this->_parseArrayIndex($strTokens, $strPtr));
266
+		try {
267
+			while (1) {
268
+				$startStrPtr = $strPtr;
269
+				$indexes [] = $this->_parseArrayIndex($strTokens, $strPtr);
270
+			}
271
+		} catch (Exception $err) {
272
+			if (0 !== ($strPtr - $startStrPtr)) {
273
+				throw $err;
274
+			}
275
+			return $indexes;
276
+		}
277
+	}//end _parseArrayIndexes()
278
+
279
+
280
+	/**
281
+	 * Grammar rule to parse the use of array index.
282
+	 *
283
+	 * _parseArrayIndex ::= [<index>]
284
+	 *
285
+	 * @exception Exception raised if $strTokens starting from $strPtr
286
+	 *                      doesn't matched the rule.
287
+	 *
288
+	 * @param array $strTokens Tokens to parse.
289
+	 * @param int   $strPtr    Pointer to the token where parsing starts.
290
+	 *
291
+	 * @return string Index between the 2 square brackets
292
+	 */
293
+	private function _parseArrayIndex ($strTokens, &$strPtr)
294
+	{
295
+		if ('[' !== $strTokens[$strPtr]) {
296
+			throw new Exception ('Expected [.');
297
+		}
298
+		$strPtr++;
299
+		if (! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER))) {
300
+			throw new Exception ('Expected an array index.');
301
+		}
302
+		$index = $strTokens[$strPtr][1];
303
+		$strPtr++;
304
+		if (']' !== $strTokens[$strPtr]) {
305
+			throw new Exception ('Expected ].');
306
+		}
307
+		$strPtr++;
308
+		return $index;
309
+	}//end _parseArrayIndex()
310
+
311
+}//end class
312
+
313
+/**
314
+ * CodeIgniter_Sniffs_Strings_VariableUsageSniff.
315
+ *
316
+ * Ensures that variables parsed in double-quoted strings are enclosed with
317
+ * braces to prevent greedy token parsing.
318
+ * Single-quoted strings don't parse variables, so there is no risk of greedy
319
+ * token parsing.
320
+ *
321
+ * @category  PHP
322
+ * @package   PHP_CodeSniffer
323
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
324
+ * @copyright 2011 Thomas Ernest
325
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
326
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
327
+ */
328
+class DoubleQuoteUsageSniff extends VariableUsageSniff
329
+{
330
+    /**
331
+     * Returns an array of tokens this test wants to listen for.
332
+     *
333
+     * @return array
334
+     */
335
+    public function register()
336
+    {
337
+        return array(
338
+            T_DOUBLE_QUOTED_STRING,
339
+            T_CONSTANT_ENCAPSED_STRING,
340
+        );
341
+    }//end register()
342
+
343
+    /**
344
+     * Processes this test, when one of its tokens is encountered.
345
+     *
346
+     * @param File $phpcsFile The current file being scanned.
347
+     * @param int                  $stackPtr  The position of the current token
348
+     *                                        in the stack passed in $tokens.
349
+     *
350
+     * @return void
351
+     */
352
+    public function process(File $phpcsFile, $stackPtr)
353
+    {
354
+        // no variable are in the string from here
355
+        $tokens = $phpcsFile->getTokens();
356
+        $qtString = $tokens[$stackPtr]['content'];
357
+        // makes sure that it is about a double quote string,
358
+        // since variables are not parsed out of double quoted string
359
+        $open_qt_str = substr($qtString, 0, 1);
360
+
361
+        // clean the enclosing quotes
362
+        $qtString = substr($qtString, 1, strlen($qtString) - 1 - 1);
363
+
364
+        if (0 === strcmp($open_qt_str, '"')) {
365
+            $this->processDoubleQuotedString($phpcsFile, $stackPtr, $qtString);
366
+        } else if (0 === strcmp($open_qt_str, "'")) {
367
+            $this->processSingleQuotedString($phpcsFile, $stackPtr, $qtString);
368
+        }
369
+    }//end process()
370
+
371
+
372
+    /**
373
+     * Processes this test, when the token encountered is a double-quoted string.
374
+     *
375
+     * @param File $phpcsFile The current file being scanned.
376
+     * @param int                  $stackPtr  The position of the current token
377
+     *                                        in the stack passed in $tokens.
378
+     * @param string               $qtString  The double-quoted string content,
379
+     *                                        i.e. without quotes.
380
+     *
381
+     * @return void
382
+     */
383
+    protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $qtString)
384
+    {
385
+        // so there should be at least a single quote or a special char
386
+        // if there are the 2 kinds of quote and no special char, then add a warning
387
+        $has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"'.$qtString.'"');
388
+        $has_specific_sequence = $this->_hasSpecificSequence($qtString);
389
+        $dbl_qt_at = strpos($qtString, '"');
390
+        $smpl_qt_at = strpos($qtString, "'");
391
+        if (false === $has_variable && false === $has_specific_sequence
392
+            && false === $smpl_qt_at
393
+        ) {
394
+            $error = 'Single-quoted strings should be used unless it contains variables, special chars like \n or single quotes.';
395
+            $phpcsFile->addError($error, $stackPtr);
396
+        } else if (false !== $smpl_qt_at && false !== $dbl_qt_at
397
+            && false === $has_variable && false === $has_specific_sequence
398
+        ) {
399
+            $warning = 'It is encouraged to use a single-quoted string, since it doesn\'t contain any variable nor special char though it mixes single and double quotes.';
400
+            $phpcsFile->addWarning($warning, $stackPtr);
401
+        }
402
+    }//end processDoubleQuotedString()
403
+
404
+
405
+    /**
406
+     * Processes this test, when the token encountered is a single-quoted string.
407
+     *
408
+     * @param File $phpcsFile The current file being scanned.
409
+     * @param int                  $stackPtr  The position of the current token
410
+     *                                        in the stack passed in $tokens.
411
+     * @param string               $qtString  The single-quoted string content,
412
+     *                                        i.e. without quotes.
413
+     *
414
+     * @return void
415
+     */
416
+    protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $qtString)
417
+    {
418
+        // if there is single quotes without additional double quotes,
419
+        // then user is allowed to use double quote to avoid having to
420
+        // escape single quotes. Don't add the warning, if an error was
421
+        // already added, because a variable was found in a single-quoted
422
+        // string.
423
+        $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'");
424
+        $dbl_qt_at = strpos($qtString, '"');
425
+        $smpl_qt_at = strpos($qtString, "'");
426
+        if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) {
427
+            $warning = 'You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.';
428
+            $phpcsFile->addWarning($warning, $stackPtr);
429
+        }
430
+    }//end processSingleQuotedString()
431
+
432
+    /**
433
+     * Return TRUE, if a sequence of chars that is parsed in a specific way
434
+     * in double-quoted strings is found, FALSE otherwise.
435
+     *
436
+     * @param string $string String in which sequence of special chars will
437
+     * be researched.
438
+     *
439
+     * @return TRUE, if a sequence of chars that is parsed in a specific way
440
+     * in double-quoted strings is found, FALSE otherwise.
441
+     *
442
+     * @link http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double
443
+     */
444
+    private function _hasSpecificSequence($string)
445
+    {
446
+        $hasSpecificSequence = FALSE;
447
+        $specialMeaningStrs = array('\n', '\r', '\t', '\v', '\f');
448
+        foreach ($specialMeaningStrs as $splStr) {
449
+            if (FALSE !== strpos($string, $splStr)) {
450
+                $hasSpecificSequence = TRUE;
451
+            }
452
+        }
453
+        $specialMeaningPtrns = array('\[0-7]{1,3}', '\x[0-9A-Fa-f]{1,2}');
454
+        foreach ($specialMeaningPtrns as $splPtrn) {
455
+            if (1 === preg_match("/{$splPtrn}/", $string)) {
456
+                $hasSpecificSequence = TRUE;
457
+            }
458
+        }
459
+        return $hasSpecificSequence;
460
+    }//end _hasSpecificSequence()
461
+
462
+}//end class
463
+
464
+?>

+ 87
- 0
build/CodeIgniter/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php View File

@@ -0,0 +1,87 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@gmail.com>
10
+ * @copyright 2011 Thomas ERNEST
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
17
+ *
18
+ * Ensures the use of tabs for indentation.
19
+ *
20
+ * @category  PHP
21
+ * @package   PHP_CodeSniffer
22
+ * @author    Thomas Ernest <thomas.ernest@gmail.com>
23
+ * @copyright 2011 Thomas ERNEST
24
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
26
+ */
27
+
28
+namespace CodeIgniter\Sniffs\WhiteSpace;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class DisallowSpaceIndentSniff implements Sniff
34
+{
35
+
36
+    /**
37
+     * A list of tokenizers this sniff supports.
38
+     *
39
+     * @var array
40
+     */
41
+    public $supportedTokenizers = array(
42
+                                   'PHP',
43
+                                   'JS',
44
+                                   'CSS',
45
+                                  );
46
+
47
+
48
+    /**
49
+     * Returns an array of tokens this test wants to listen for.
50
+     *
51
+     * @return array
52
+     */
53
+    public function register()
54
+    {
55
+        return array(T_WHITESPACE);
56
+    }//end register()
57
+
58
+
59
+    /**
60
+     * Processes this test, when one of its tokens is encountered.
61
+     *
62
+     * @param File $phpcsFile All the tokens found in the document.
63
+     * @param int                  $stackPtr  The position of the current token
64
+     *                                        in the stack passed in $tokens.
65
+     *
66
+     * @return void
67
+     */
68
+    public function process(File $phpcsFile, $stackPtr)
69
+    {
70
+        $tokens = $phpcsFile->getTokens();
71
+
72
+        // Make sure this is whitespace used for indentation.
73
+        $line = $tokens[$stackPtr]['line'];
74
+        if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
75
+            return;
76
+        }
77
+
78
+        if (strpos($tokens[$stackPtr]['content'], " ") !== false) {
79
+            $error = 'Tabs must be used to indent lines; spaces are not allowed for code indentation';
80
+            $phpcsFile->addError($error, $stackPtr, 'SpacesUsedForIndentation');
81
+        }
82
+    }//end process()
83
+
84
+
85
+}//end class
86
+
87
+?>

+ 95
- 0
build/CodeIgniter/Sniffs/WhiteSpace/DisallowWitheSpaceAroundPhpTagsSniff.php View File

@@ -0,0 +1,95 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_WhiteSpace_DisallowWitheSpaceAroundPhpTagsSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_WhiteSpace_DisallowWitheSpaceAroundPhpTagsSniff.
17
+ *
18
+ * Ensures that no whitespace precedes the opening PHP tag
19
+ * or follows the closing PHP tag.
20
+ *
21
+ * @category  PHP
22
+ * @package   PHP_CodeSniffer
23
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
24
+ * @copyright 2006 Thomas Ernest
25
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
26
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
27
+ */
28
+
29
+namespace CodeIgniter\Sniffs\WhiteSpace;
30
+
31
+use PHP_CodeSniffer\Sniffs\Sniff;
32
+use PHP_CodeSniffer\Files\File;
33
+
34
+class DisallowWitheSpaceAroundPhpTagsSniff implements Sniff
35
+{
36
+
37
+    /**
38
+     * Returns an array of tokens this test wants to listen for.
39
+     *
40
+     * @return array
41
+     */
42
+    public function register()
43
+    {
44
+        return array(
45
+                T_OPEN_TAG,
46
+                T_CLOSE_TAG
47
+               );
48
+
49
+    }//end register()
50
+
51
+
52
+    /**
53
+     * Processes this test, when one of its tokens is encountered.
54
+     *
55
+     * @param File $phpcsFile The current file being scanned.
56
+     * @param int                  $stackPtr  The position of the current token
57
+     *                                        in the stack passed in $tokens.
58
+     *
59
+     * @return void
60
+     */
61
+    public function process(File $phpcsFile, $stackPtr)
62
+    {
63
+        $tokens = $phpcsFile->getTokens();
64
+
65
+        $php_tag_token = $tokens[$stackPtr];
66
+        $php_tag_code = $php_tag_token['code'];
67
+
68
+        if (T_OPEN_TAG === $php_tag_code) {
69
+            // opening php tag should be the first token.
70
+            // any whitespace beofre an opening php tag is tokenized
71
+            // as T_INLINE_HTML, so no need to check the content of the token.
72
+            $isFirst = 0 === $stackPtr;
73
+            if ( ! $isFirst) {
74
+                $error = 'Any char before the opening PHP tag is prohibited. Please remove newline or indentation before the opening PHP tag.';
75
+                $phpcsFile->addError($error, $stackPtr);
76
+            }
77
+        } else {
78
+            // if (T_CLOSE_TAG === $php_tag_code)
79
+            // closing php tag should be the last token
80
+            // and it must not contain any whitespace.
81
+            $php_tag_string = $php_tag_token['content'];
82
+            $isLast = count($tokens) - 1 === $stackPtr;
83
+            // both of the two closing php tags contains 2 chars exactly.
84
+            $containsEndTagOnly = strlen($php_tag_string) > 2;
85
+            if ( ! $isLast || ! $containsEndTagOnly ) {
86
+                $error = 'Any char after the closing PHP tag is prohibited. Please removes newline or spaces after the closing PHP tag.';
87
+                $phpcsFile->addError($error, $stackPtr);
88
+            }
89
+        }
90
+    }//end process()
91
+
92
+
93
+}//end class
94
+
95
+?>

+ 82
- 0
build/CodeIgniter/Sniffs/WhiteSpace/ElseOnNewLineSniff.php View File

@@ -0,0 +1,82 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_WhiteSpace_ElseOnNewLineSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_WhiteSpace_ElseOnNewLineSniff.
17
+ *
18
+ * Ensures that control structures else and elseif stand on new lines.
19
+ *
20
+ * @category  PHP
21
+ * @package   PHP_CodeSniffer
22
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
23
+ * @copyright 2006 Thomas Ernest
24
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
26
+ */
27
+
28
+namespace CodeIgniter\Sniffs\WhiteSpace;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class ElseOnNewLineSniff implements Sniff
34
+{
35
+
36
+    /**
37
+     * Returns an array of tokens this test wants to listen for.
38
+     *
39
+     * @return array
40
+     */
41
+    public function register()
42
+    {
43
+        return array(
44
+            T_ELSE,
45
+            T_ELSEIF,
46
+        );
47
+    }//end register()
48
+
49
+
50
+    /**
51
+     * Processes this test, when one of its tokens is encountered.
52
+     *
53
+     * @param File $phpcsFile The current file being scanned.
54
+     * @param int                  $stackPtr  The position of the current token
55
+     *                                        in the stack passed in $tokens.
56
+     *
57
+     * @return void
58
+     */
59
+    public function process(File $phpcsFile, $stackPtr)
60
+    {
61
+        $tokens = $phpcsFile->getTokens();
62
+
63
+        $else_token = $tokens[$stackPtr];
64
+        $previous_non_blank_token_ptr = $phpcsFile->findPrevious(array(T_WHITESPACE), $stackPtr - 1, null, true);
65
+
66
+        if (false === $previous_non_blank_token_ptr) {
67
+        	// else is no preceded with any symbol, but it is not the responsibility of this sniff.
68
+        	return;
69
+        }
70
+
71
+        $previous_non_blank_token = $tokens[$previous_non_blank_token_ptr];
72
+        if ($previous_non_blank_token['line'] === $else_token['line']) {
73
+            $error = '"' . $else_token['content'] . '" should be on a new line.';
74
+            $phpcsFile->addError($error, $stackPtr);
75
+        }
76
+
77
+    }//end process()
78
+
79
+
80
+}//end class
81
+
82
+?>

+ 75
- 0
build/CodeIgniter/Sniffs/WhiteSpace/LogicalNotSpacingSniff.php View File

@@ -0,0 +1,75 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_WhiteSpace_LogicalNotSpacingSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_WhiteSpace_LogicalNotSpacingSniff.
17
+ *
18
+ * Ensures that at exactly a space precedes and follows the logical operator !.
19
+ *
20
+ * @category  PHP
21
+ * @package   PHP_CodeSniffer
22
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
23
+ * @copyright 2006 Thomas Ernest
24
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
26
+ */
27
+
28
+namespace CodeIgniter\Sniffs\WhiteSpace;
29
+
30
+use PHP_CodeSniffer\Sniffs\Sniff;
31
+use PHP_CodeSniffer\Files\File;
32
+
33
+class LogicalNotSpacingSniff implements Sniff
34
+{
35
+
36
+    /**
37
+     * Returns an array of tokens this test wants to listen for.
38
+     *
39
+     * @return array
40
+     */
41
+    public function register()
42
+    {
43
+        return array(
44
+            T_BOOLEAN_NOT,
45
+        );
46
+    }//end register()
47
+
48
+
49
+    /**
50
+     * Processes this test, when one of its tokens is encountered.
51
+     *
52
+     * @param File $phpcsFile The current file being scanned.
53
+     * @param int                  $stackPtr  The position of the current token
54
+     *                                        in the stack passed in $tokens.
55
+     *
56
+     * @return void
57
+     */
58
+    public function process(File $phpcsFile, $stackPtr)
59
+    {
60
+        $tokens = $phpcsFile->getTokens();
61
+
62
+        $operator_token = $tokens[$stackPtr];
63
+
64
+        $previous_token = $tokens[$stackPtr - 1];
65
+        $next_token = $tokens[$stackPtr + 1];
66
+        if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) {
67
+            $error = 'Logical operator ! should always be preceded and followed with a whitespace.';
68
+            $phpcsFile->addError($error, $stackPtr);
69
+        }
70
+    }//end process()
71
+
72
+
73
+}//end class
74
+
75
+?>

+ 104
- 0
build/CodeIgniter/UnusedSniffs/Files/AbstractClosingCommentSniff.php View File

@@ -0,0 +1,104 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Files_AbstractClosingCommentSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Files_AbstractClosingCommentSniff.
17
+ *
18
+ * Defines some methods used by
19
+ * CodeIgniter_Sniffs_Files_ClosingFileCommentSniff
20
+ * and CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff.
21
+ *
22
+ * @category  PHP
23
+ * @package   PHP_CodeSniffer
24
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
25
+ * @copyright 2006 Thomas Ernest
26
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
27
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
28
+ */
29
+
30
+namespace CodeIgniter\Sniffs\Files;
31
+
32
+use PHP_CodeSniffer\Sniffs\Sniff;
33
+use PHP_CodeSniffer\Files\File;
34
+
35
+class AbstractClosingCommentSniff implements Sniff
36
+{
37
+    /**
38
+     * As an abstract class, this sniff is not associated to any token.
39
+     */
40
+    public function register()
41
+    {
42
+      return array();
43
+    }
44
+
45
+    /**
46
+     * As an abstract class, this sniff is not dedicated to process a token.
47
+     */
48
+    public function process(File $phpcsFile, $stackPtr)
49
+    {
50
+      $error = __CLASS__.'::'.__METHOD__.' is abstract. Please develop this method in a child class.';
51
+      throw new PHP_CodeSniffer_Exception($error);
52
+    }
53
+
54
+    /**
55
+     * Returns the comment without its delimiter(s) as well as leading
56
+     * and traling whitespaces.
57
+     *
58
+     * It removes the first #, the two first / (i.e. //) or the first /*
59
+     * and last \*\/. If a comment starts with /**, then the last * will remain
60
+     * as well as whitespaces between this star and the comment content.
61
+     *
62
+     * @param string $comment Comment containing either comment delimiter(s) and
63
+     * trailing or leading whitspaces to clean.
64
+     *
65
+     * @return string Comment without comment delimiter(s) and whitespaces.
66
+     */
67
+    protected static function _getCommentContent ($comment)
68
+    {
69
+        if (self::_stringStartsWith($comment, '#')) {
70
+            $comment = substr($comment, 1);
71
+        } else if (self::_stringStartsWith($comment, '//')) {
72
+            $comment = substr($comment, 2);
73
+        } else if (self::_stringStartsWith($comment, '/*')) {
74
+            $comment = substr($comment, 2, strlen($comment) - 2 - 2);
75
+        }
76
+        $comment = trim($comment);
77
+        return $comment;
78
+    }//_getCommentContent()
79
+
80
+
81
+    /**
82
+     * Binary safe string comparison between $needle and
83
+     * the beginning of $haystack. Returns true if $haystack starts with
84
+     * $needle, false otherwise.
85
+     *
86
+     * @param string $haystack The string to search in.
87
+     * @param string $needle   The string to search for.
88
+     *
89
+     * @return bool true if $haystack starts with $needle, false otherwise.
90
+     */
91
+    protected static function _stringStartsWith ($haystack, $needle)
92
+    {
93
+        $startsWith = false;
94
+        if (strlen($needle) <= strlen($haystack)) {
95
+            $haystackBeginning = substr($haystack, 0, strlen($needle));
96
+            if (0 === strcmp($haystackBeginning, $needle)) {
97
+                $startsWith = true;
98
+            }
99
+        }
100
+        return $startsWith;
101
+    }//_stringStartsWith()
102
+}//end class
103
+
104
+?>

+ 109
- 0
build/CodeIgniter/UnusedSniffs/Files/ClosingFileCommentSniff.php View File

@@ -0,0 +1,109 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Files_ClosingFileCommentSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Files_ClosingFileCommentSniff.
17
+ *
18
+ * Ensures that a comment containing the file name is available at the end of file.
19
+ * Only other comments and whitespaces are allowed to follow this specific comment.
20
+ *
21
+ * It may be all kind of comment like multi-line and inline C-style comments as
22
+ * well as PERL-style comments. Any number of white may separate comment delimiters
23
+ * from comment content. However, content has to be equal to template
24
+ * "End of file <file_name>". Comparison between content and template is
25
+ * case-sensitive.
26
+ *
27
+ * @category  PHP
28
+ * @package   PHP_CodeSniffer
29
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
30
+ * @copyright 2006 Thomas Ernest
31
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
32
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
33
+ */
34
+
35
+namespace CodeIgniter\Sniffs\Files;
36
+
37
+use PHP_CodeSniffer\Files\File;
38
+
39
+class ClosingFileCommentSniff extends AbstractClosingCommentSniff
40
+{
41
+
42
+    /**
43
+     * Returns an array of tokens this test wants to listen for.
44
+     *
45
+     * @return array
46
+     */
47
+    public function register()
48
+    {
49
+        return array(
50
+            T_OPEN_TAG,
51
+        );
52
+
53
+    }//end register()
54
+
55
+
56
+    /**
57
+     * Processes this test, when one of its tokens is encountered.
58
+     *
59
+     * @param File $phpcsFile The current file being scanned.
60
+     * @param int                  $stackPtr  The position of the current token
61
+     *                                        in the stack passed in $tokens.
62
+     *
63
+     * @return void
64
+     */
65
+    public function process(File $phpcsFile, $stackPtr)
66
+    {
67
+        // We are only interested if this is the first open tag.
68
+        if ($stackPtr !== 0) {
69
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
70
+                return;
71
+            }
72
+        }
73
+
74
+        $fullFilename = $phpcsFile->getFilename();
75
+        $filename = basename($fullFilename);
76
+        $commentTemplate = "End of file $filename";
77
+
78
+        $tokens = $phpcsFile->getTokens();
79
+        $currentToken = count($tokens) - 1;
80
+        $hasClosingFileComment = false;
81
+        $isNotAWhitespaceOrAComment = false;
82
+        while ($currentToken >= 0
83
+            && ! $isNotAWhitespaceOrAComment
84
+            && ! $hasClosingFileComment
85
+        ) {
86
+            $token = $tokens[$currentToken];
87
+            $tokenCode = $token['code'];
88
+            if (T_COMMENT === $tokenCode) {
89
+                $commentString = self::_getCommentContent($token['content']);
90
+                if (0 === strcmp($commentString, $commentTemplate)) {
91
+                    $hasClosingFileComment = true;
92
+                }
93
+            } else if (T_WHITESPACE === $tokenCode) {
94
+                // Whitespaces are allowed between the closing file comment,
95
+                // other comments and end of file
96
+            } else {
97
+                $isNotAWhitespaceOrAComment = true;
98
+            }
99
+            $currentToken--;
100
+        }
101
+
102
+        if ( ! $hasClosingFileComment) {
103
+            $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".';
104
+            $phpcsFile->addError($error, $currentToken);
105
+        }
106
+    }//end process()
107
+}//end class
108
+
109
+?>

+ 182
- 0
build/CodeIgniter/UnusedSniffs/Files/ClosingLocationCommentSniff.php View File

@@ -0,0 +1,182 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
10
+ * @copyright 2006 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+/**
16
+ * CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff.
17
+ *
18
+ * Ensures that a comment containing the file location exists at the end of file.
19
+ * Only other comments and whitespaces are allowed between this comment and
20
+ * the end of file.
21
+ *
22
+ * It may be all kind of comment like multi-line and inline C-style comments as
23
+ * well as PERL-style comments. Any number of white may separate comment delimiters
24
+ * from comment content. However, content has to be equal to template
25
+ * "Location: <file_path_relative_to_application_root>".
26
+ * Comparison between content and template is case-sensitive.
27
+ *
28
+ * There are several ways to configure the application root. In order of priority :
29
+ *   - Configuration variable ci_application_root.
30
+ *   - Rule property applicationRoot.
31
+ *   - Default value '/application/'
32
+ *
33
+ * @category  PHP
34
+ * @package   PHP_CodeSniffer
35
+ * @author    Thomas Ernest <thomas.ernest@baobaz.com>
36
+ * @copyright 2006 Thomas Ernest
37
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
38
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
39
+ */
40
+
41
+namespace CodeIgniter\Sniffs\Files;
42
+
43
+use PHP_CodeSniffer\Files\File;
44
+use PHP_CodeSniffer\Util\Common;
45
+
46
+class ClosingLocationCommentSniff extends AbstractClosingCommentSniff
47
+{
48
+    public $applicationRoot = '/application/';
49
+
50
+    /**
51
+     * Returns an array of tokens this test wants to listen for.
52
+     *
53
+     * @return array
54
+     */
55
+    public function register()
56
+    {
57
+        return array(
58
+            T_OPEN_TAG
59
+        );
60
+
61
+    }//end register()
62
+
63
+
64
+    /**
65
+     * Processes this test, when one of its tokens is encountered.
66
+     *
67
+     * @param File $phpcsFile The current file being scanned.
68
+     * @param int                  $stackPtr  The position of the current token
69
+     *                                        in the stack passed in $tokens.
70
+     *
71
+     * @return void
72
+     */
73
+    public function process(File $phpcsFile, $stackPtr)
74
+    {
75
+        // We are only interested if this is the first open tag.
76
+        if ($stackPtr !== 0) {
77
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
78
+                return;
79
+            }
80
+        }
81
+
82
+        $filePath = $phpcsFile->getFilename();
83
+        $tokens = $phpcsFile->getTokens();
84
+        // removes the application root from the beginning of the file path
85
+        $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot());
86
+        // add an error, if application root doesn't exist in current file path
87
+        if (false === $locationPath) {
88
+            $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.';
89
+            $phpcsFile->addError($error, count($tokens) - 1);
90
+            return;
91
+        }
92
+        // generates the expected comment
93
+        $commentTemplate = "Location: $locationPath";
94
+
95
+        $currentToken = count($tokens) - 1;
96
+        $hasClosingLocationComment = false;
97
+        $isNotAWhitespaceOrAComment = false;
98
+        while ($currentToken >= 0
99
+            && ! $isNotAWhitespaceOrAComment
100
+            && ! $hasClosingLocationComment
101
+        ) {
102
+            $token = $tokens[$currentToken];
103
+            $tokenCode = $token['code'];
104
+            if (T_COMMENT === $tokenCode) {
105
+                $commentString = self::_getCommentContent($token['content']);
106
+                if (0 === strcmp($commentString, $commentTemplate)) {
107
+                    $hasClosingLocationComment = true;
108
+                }
109
+            } else if (T_WHITESPACE === $tokenCode) {
110
+                // Whitespaces are allowed between the closing file comment,
111
+                //other comments and end of file
112
+            } else {
113
+                $isNotAWhitespaceOrAComment = true;
114
+            }
115
+            $currentToken--;
116
+        }
117
+
118
+        if ( ! $hasClosingLocationComment) {
119
+            $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".';
120
+            $phpcsFile->addError($error, $currentToken);
121
+        }
122
+    }//end process()
123
+
124
+
125
+    /**
126
+     * Returns the relative path from $appRoot to $filePath, or false if
127
+     * $appRoot cannot be found in $filePath, because $appRoot is not a parent
128
+     * of $filePath.
129
+     *
130
+     * @param string $filePath Full path to the file being proceed.
131
+     * @param string $appRoot  Partial or full path to the CodeIgniter
132
+     * application root of the file being proceed. It must not contain the
133
+     * full path to the application root, but at least the name of the
134
+     * application root. Parent directory of the application root are allowed
135
+     * but not mandatory.
136
+     *
137
+     * @return string|bool The relative path from $appRoot to $filePath, or
138
+     * false if $appRoot cannot be found in $filePath.
139
+     */
140
+    private static function _getLocationPath ($filePath, $appRoot)
141
+    {
142
+        // removes the path to application root
143
+        // from the beginning of the file path
144
+        $appRootAt = strpos($filePath, $appRoot);
145
+        if (false === $appRootAt) {
146
+            return false;
147
+        }
148
+        $localPath = substr($filePath, $appRootAt + strlen($appRoot));
149
+        // ensures the location path to be a relative path starting with "./".
150
+        if ( ! self::_stringStartsWith($localPath, './')) {
151
+            $localPath = './' . $localPath;
152
+        } else if ( ! self::_stringStartsWith($localPath, '.')
153
+            && self::_stringStartsWith($localPath, '/')
154
+        ) {
155
+            $localPath = '.' . $localPath;
156
+        }
157
+        return $localPath;
158
+    }//end _getLocationPath()
159
+
160
+
161
+    /**
162
+     * Returns the application root that should be used first.
163
+     *
164
+     * There are several ways to configure the application root.
165
+     * In order of priority :
166
+     *   - Configuration variable ci_application_root.
167
+     *   - Rule property applicationRoot.
168
+     *   - Default value '/application/'
169
+     *
170
+     * @return string Path to your project application root.
171
+     */
172
+    private function _getAppRoot()
173
+    {
174
+        $appRoot = Common::getConfigData('ci_application_root');
175
+        if (null === $appRoot) {
176
+            $appRoot = $this->applicationRoot;
177
+        }
178
+        return $appRoot;
179
+    }//end _getAppRoot()
180
+}//end class
181
+
182
+?>

+ 142
- 0
build/CodeIgniter/UnusedSniffs/NamingConventions/ConstructorNameSniff.php View File

@@ -0,0 +1,142 @@
1
+<?php
2
+/**
3
+ * CodeIgniter_Sniffs_NamingConventions_ConstructorNameSniff.
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category  PHP
8
+ * @package   PHP_CodeSniffer
9
+ * @author    Thomas Ernest <thomas.ernest@gmail.com>
10
+ * @copyright 2011 Thomas Ernest
11
+ * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
+ * @link      http://pear.php.net/package/PHP_CodeSniffer
13
+ */
14
+
15
+namespace CodeIgniter\Sniffs\NamingConventions;
16
+
17
+use PHP_CodeSniffer\Sniffs\AbstractScopeSniff;
18
+use PHP_CodeSniffer\Files\File;
19
+
20
+/**
21
+ * CodeIgniter_Sniffs_NamingConventions_ConstructorNameSniff.
22