Skip to content
This repository was archived by the owner on Jan 1, 2020. It is now read-only.

Commit af7e58a

Browse files
committed
fixed coding standards
1 parent 04e3f18 commit af7e58a

File tree

317 files changed

+35819
-37331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

317 files changed

+35819
-37331
lines changed

_lizenz.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Additions and fixes Copyright (c) 2012 Robert Wetzlmayr http://wetzlmayr.com
6060
// ----- addons/import_export/classes/class.tar.inc.php
6161

6262
TAR File Manager
63-
Base name: tarmanager
63+
Base name: tarmanager
6464
Copyright (C) 2002 Josh Barger
6565
License: GNU Lesser General Public License (LGPL)
6666
Description: A PHP Implementation of the TAR Format manager.

coding_standards.php

+146-147
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// modified coding_standards script, only checks line endings and encoding
55

66
if (PHP_SAPI !== 'cli') {
7-
echo 'error: this script may only be run from CLI', PHP_EOL;
8-
exit(1);
7+
echo 'error: this script may only be run from CLI', PHP_EOL;
8+
exit(1);
99
}
1010

1111
stream_set_blocking(STDIN, 0);
@@ -20,148 +20,147 @@
2020
echo PHP_EOL, PHP_EOL;
2121

2222
if (!isset($argv[1]) || !in_array($argv[1], array('fix', 'check'))) {
23-
echo 'Usage:
24-
php ', $argv[0], ' <mode> [options]
25-
php ', $argv[0], ' <mode> <path> [options]
26-
php ', $argv[0], ' <mode> package <package> [options]
23+
echo 'Usage:
24+
php ', $argv[0], ' <mode> [options]
25+
php ', $argv[0], ' <mode> <path> [options]
26+
php ', $argv[0], ' <mode> package <package> [options]
2727
28-
<mode> "check" or "fix"
29-
<path> path to a directory or a file
30-
<package> package id ("addonname" or "addonname/pluginname")
28+
<mode> "check" or "fix"
29+
<path> path to a directory or a file
30+
<package> package id ("addonname" or "addonname/pluginname")
3131
32-
options:
33-
--hide-process: Don\'t show current checking file path', PHP_EOL, PHP_EOL;
32+
options:
33+
--hide-process: Don\'t show current checking file path', PHP_EOL, PHP_EOL;
3434

35-
exit(1);
35+
exit(1);
3636
}
3737

3838
class rex_coding_standards_fixer
3939
{
40-
protected
41-
$content,
42-
$fixable = array(),
43-
$nonFixable = array();
44-
45-
public function __construct($content)
46-
{
47-
$this->content = $content;
48-
49-
$this->fix();
50-
}
51-
52-
public function hasChanged()
53-
{
54-
return !empty($this->fixable) || !empty($this->nonFixable);
55-
}
56-
57-
public function getFixable()
58-
{
59-
return array_keys($this->fixable);
60-
}
61-
62-
public function getNonFixable()
63-
{
64-
return array_keys($this->nonFixable);
65-
}
66-
67-
public function getResult()
68-
{
69-
return $this->content;
70-
}
71-
72-
protected function addFixable($fixable)
73-
{
74-
$this->fixable[$fixable] = true;
75-
}
76-
77-
protected function addNonFixable($nonFixable)
78-
{
79-
$this->nonFixable[$nonFixable] = true;
80-
}
81-
82-
protected function fix()
83-
{
84-
if (($encoding = mb_detect_encoding($this->content, 'UTF-8,ISO-8859-1,WINDOWS-1252')) != 'UTF-8') {
85-
if ($encoding === false) {
86-
$encoding = mb_detect_encoding($this->content);
87-
}
88-
if ($encoding !== false) {
89-
$this->content = iconv($encoding, 'UTF-8', $this->content);
90-
$this->addFixable('fix encoding from ' . $encoding . ' to UTF-8');
91-
} else {
92-
$this->addNonFixable('couldn\'t detect encoding, change it to UTF-8');
93-
}
94-
} elseif (strpos($this->content, "\xEF\xBB\xBF") === 0) {
95-
$this->content = substr($this->content, 3);
96-
$this->addFixable('remove BOM (Byte Order Mark)');
40+
protected $content;
41+
protected $fixable = array();
42+
protected $nonFixable = array();
43+
44+
public function __construct($content)
45+
{
46+
$this->content = $content;
47+
48+
$this->fix();
49+
}
50+
51+
public function hasChanged()
52+
{
53+
return !empty($this->fixable) || !empty($this->nonFixable);
9754
}
9855

99-
if (strpos($this->content, "\r") !== false) {
100-
$this->content = str_replace(array("\r\n", "\r"), "\n", $this->content);
101-
$this->addFixable('fix line endings to LF');
56+
public function getFixable()
57+
{
58+
return array_keys($this->fixable);
10259
}
10360

104-
/*if (strpos($this->content, "\t") !== false) {
105-
$this->content = str_replace("\t", ' ', $this->content);
106-
$this->addFixable('convert tabs to spaces');
61+
public function getNonFixable()
62+
{
63+
return array_keys($this->nonFixable);
10764
}
10865

109-
if (preg_match('/ $/m', $this->content)) {
110-
$this->content = preg_replace('/ +$/m', '', $this->content);
111-
$this->addFixable('remove trailing whitespace');
66+
public function getResult()
67+
{
68+
return $this->content;
11269
}
11370

114-
if (strlen($this->content) && substr($this->content, -1) != "\n") {
115-
$this->content .= "\n";
116-
$this->addFixable('add newline at end of file');
71+
protected function addFixable($fixable)
72+
{
73+
$this->fixable[$fixable] = true;
11774
}
11875

119-
if (preg_match("/\n{2,}$/", $this->content)) {
120-
$this->content = rtrim($this->content, "\n") . "\n";
121-
$this->addFixable('remove multiple newlines at end of file');
122-
}*/
123-
}
76+
protected function addNonFixable($nonFixable)
77+
{
78+
$this->nonFixable[$nonFixable] = true;
79+
}
80+
81+
protected function fix()
82+
{
83+
if (($encoding = mb_detect_encoding($this->content, 'UTF-8,ISO-8859-1,WINDOWS-1252')) != 'UTF-8') {
84+
if ($encoding === false) {
85+
$encoding = mb_detect_encoding($this->content);
86+
}
87+
if ($encoding !== false) {
88+
$this->content = iconv($encoding, 'UTF-8', $this->content);
89+
$this->addFixable('fix encoding from ' . $encoding . ' to UTF-8');
90+
} else {
91+
$this->addNonFixable('couldn\'t detect encoding, change it to UTF-8');
92+
}
93+
} elseif (strpos($this->content, "\xEF\xBB\xBF") === 0) {
94+
$this->content = substr($this->content, 3);
95+
$this->addFixable('remove BOM (Byte Order Mark)');
96+
}
97+
98+
if (strpos($this->content, "\r") !== false) {
99+
$this->content = str_replace(array("\r\n", "\r"), "\n", $this->content);
100+
$this->addFixable('fix line endings to LF');
101+
}
102+
103+
/*if (strpos($this->content, "\t") !== false) {
104+
$this->content = str_replace("\t", ' ', $this->content);
105+
$this->addFixable('convert tabs to spaces');
106+
}
107+
108+
if (preg_match('/ $/m', $this->content)) {
109+
$this->content = preg_replace('/ +$/m', '', $this->content);
110+
$this->addFixable('remove trailing whitespace');
111+
}
112+
113+
if (strlen($this->content) && substr($this->content, -1) != "\n") {
114+
$this->content .= "\n";
115+
$this->addFixable('add newline at end of file');
116+
}
117+
118+
if (preg_match("/\n{2,}$/", $this->content)) {
119+
$this->content = rtrim($this->content, "\n") . "\n";
120+
$this->addFixable('remove multiple newlines at end of file');
121+
}*/
122+
}
124123
}
125124

126125
$fix = $argv[1] == 'fix';
127126

128127
$dir = dirname(Phar::running(false)) ?: __DIR__;
129128
$files = null;
130129
if (isset($argv[2]) && $argv[2][0] !== '-') {
131-
if ($argv[2] == 'package') {
132-
if (!isset($argv[3]) || $argv[3][0] === '-') {
133-
echo 'ERROR: Missing package id!', PHP_EOL, PHP_EOL;
134-
exit(1);
135-
}
136-
$package = $argv[3];
137-
if (strpos($package, '/') === false) {
138-
$dir .= DIRECTORY_SEPARATOR . 'redaxo' . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . $package;
139-
} else {
140-
list($addon, $plugin) = explode('/', $package, 2);
141-
$dir .= DIRECTORY_SEPARATOR . 'redaxo' . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . $addon . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $plugin;
142-
}
143-
if (!is_dir($dir)) {
144-
echo 'ERROR: Package "', $package, '" does not exist!', PHP_EOL, PHP_EOL;
145-
exit(1);
146-
}
147-
} else {
148-
if (is_dir($argv[2])) {
149-
$dir = realpath($argv[2]);
150-
} elseif (is_file($argv[2])) {
151-
$file = realpath($argv[2]);
152-
$files = array($file => $file);
153-
$dir = dirname($file);
130+
if ($argv[2] == 'package') {
131+
if (!isset($argv[3]) || $argv[3][0] === '-') {
132+
echo 'ERROR: Missing package id!', PHP_EOL, PHP_EOL;
133+
exit(1);
134+
}
135+
$package = $argv[3];
136+
if (strpos($package, '/') === false) {
137+
$dir .= DIRECTORY_SEPARATOR . 'redaxo' . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . $package;
138+
} else {
139+
list($addon, $plugin) = explode('/', $package, 2);
140+
$dir .= DIRECTORY_SEPARATOR . 'redaxo' . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . $addon . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $plugin;
141+
}
142+
if (!is_dir($dir)) {
143+
echo 'ERROR: Package "', $package, '" does not exist!', PHP_EOL, PHP_EOL;
144+
exit(1);
145+
}
154146
} else {
155-
echo 'ERROR: Directory or file "', $argv[2], '" does not exist!', PHP_EOL, PHP_EOL;
156-
exit(1);
147+
if (is_dir($argv[2])) {
148+
$dir = realpath($argv[2]);
149+
} elseif (is_file($argv[2])) {
150+
$file = realpath($argv[2]);
151+
$files = array($file => $file);
152+
$dir = dirname($file);
153+
} else {
154+
echo 'ERROR: Directory or file "', $argv[2], '" does not exist!', PHP_EOL, PHP_EOL;
155+
exit(1);
156+
}
157157
}
158-
}
159158
} elseif ($input = file('php://stdin', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) {
160-
$files = array_flip(array_map('realpath', array_filter($input, 'file_exists')));
159+
$files = array_flip(array_map('realpath', array_filter($input, 'file_exists')));
161160
}
162161

163162
if (!is_array($files)) {
164-
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::CURRENT_AS_SELF | RecursiveDirectoryIterator::SKIP_DOTS));
163+
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::CURRENT_AS_SELF | RecursiveDirectoryIterator::SKIP_DOTS));
165164
}
166165

167166
$hideProcess = in_array('--hide-process', $argv);
@@ -171,57 +170,57 @@ protected function fix()
171170
$countNonFixable = 0;
172171

173172
foreach ($files as $path => $_n) {
174-
$subPath = str_replace($dir . DIRECTORY_SEPARATOR, '', $path);
175-
$fileExt = pathinfo($path, PATHINFO_EXTENSION);
176-
if (!in_array($fileExt, $textExtensions) || strpos(DIRECTORY_SEPARATOR . $subPath, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) !== false) {
177-
continue;
178-
}
179-
180-
if (!$hideProcess) {
181-
$checkString = $subPath;
182-
if (mb_strlen($checkString) > 60) {
183-
$checkString = mb_substr($checkString, 0, 20) . '...' . mb_substr($checkString, -37);
173+
$subPath = str_replace($dir . DIRECTORY_SEPARATOR, '', $path);
174+
$fileExt = pathinfo($path, PATHINFO_EXTENSION);
175+
if (!in_array($fileExt, $textExtensions) || strpos(DIRECTORY_SEPARATOR . $subPath, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) !== false) {
176+
continue;
184177
}
185-
echo $checkString = 'check ' . $checkString . ' ...';
186-
}
187178

188-
$countFiles++;
189-
$fixer = new rex_coding_standards_fixer(file_get_contents($path));
179+
if (!$hideProcess) {
180+
$checkString = $subPath;
181+
if (mb_strlen($checkString) > 60) {
182+
$checkString = mb_substr($checkString, 0, 20) . '...' . mb_substr($checkString, -37);
183+
}
184+
echo $checkString = 'check ' . $checkString . ' ...';
185+
}
190186

191-
if (!$hideProcess) {
192-
echo str_repeat("\010 \010", mb_strlen($checkString));
193-
}
187+
$countFiles++;
188+
$fixer = new rex_coding_standards_fixer(file_get_contents($path));
194189

195-
if ($fixer->hasChanged()) {
196-
echo $subPath, ':', PHP_EOL;
197-
if ($fixable = $fixer->getFixable()) {
198-
echo ' > ', implode(PHP_EOL . ' > ', $fixable), PHP_EOL;
199-
$countFixable++;
200-
}
201-
if ($nonFixable = $fixer->getNonFixable()) {
202-
echo ' ! ', implode(PHP_EOL . ' ! ', $nonFixable), PHP_EOL;
203-
$countNonFixable++;
190+
if (!$hideProcess) {
191+
echo str_repeat("\010 \010", mb_strlen($checkString));
204192
}
205-
echo PHP_EOL;
206193

207-
if ($fix) {
208-
file_put_contents($path, $fixer->getResult());
194+
if ($fixer->hasChanged()) {
195+
echo $subPath, ':', PHP_EOL;
196+
if ($fixable = $fixer->getFixable()) {
197+
echo ' > ', implode(PHP_EOL . ' > ', $fixable), PHP_EOL;
198+
$countFixable++;
199+
}
200+
if ($nonFixable = $fixer->getNonFixable()) {
201+
echo ' ! ', implode(PHP_EOL . ' ! ', $nonFixable), PHP_EOL;
202+
$countNonFixable++;
203+
}
204+
echo PHP_EOL;
205+
206+
if ($fix) {
207+
file_put_contents($path, $fixer->getResult());
208+
}
209209
}
210-
}
211210
}
212211

213212
echo '-----------------------------------', PHP_EOL;
214213
echo 'checked ', $countFiles, ' files', PHP_EOL;
215214
if ($countFixable) {
216-
echo '', ($fix ? 'fixed' : 'found fixable'), ' problems in ', $countFixable, ' files', PHP_EOL;
215+
echo '', ($fix ? 'fixed' : 'found fixable'), ' problems in ', $countFixable, ' files', PHP_EOL;
217216
}
218217
if ($countNonFixable) {
219-
echo 'found non-fixable problems in ', $countNonFixable, ' files', PHP_EOL;
218+
echo 'found non-fixable problems in ', $countNonFixable, ' files', PHP_EOL;
220219
}
221220

222221
echo PHP_EOL;
223222
if ($hasColorSupport) {
224-
echo ($countNonFixable + ($fix ? 0 : $countFixable)) ? "\033[1;37;41m" : "\033[1;30;42m";
223+
echo ($countNonFixable + ($fix ? 0 : $countFixable)) ? "\033[1;37;41m" : "\033[1;30;42m";
225224
}
226225
echo 'FINISHED, ', !$countFixable && !$countNonFixable ? 'no problems' : 'found problems';
227226
echo $hasColorSupport ? "\033[0m" : '';

0 commit comments

Comments
 (0)