Skip to content

Commit fd9a433

Browse files
committed
code inspection and fixed
1 parent 4d23b44 commit fd9a433

29 files changed

+138
-138
lines changed

libs/Asset/AssetLoad.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ protected function handleLoad($assets, $assetType = self::TYPE_CSS)
166166
$this->compressed = false;
167167

168168
// is string
169-
if ($assets && is_string($assets)) {
169+
if ($assets && \is_string($assets)) {
170170
// 是否是以逗号连接的多个文件名
171171
$assets = (strpos($assets, ',') && false === strpos($assets, 'http')) ? explode(',', $assets) : [$assets];
172172
}
173173

174-
if (!is_array($assets)) {
174+
if (!\is_array($assets)) {
175175
throw new InvalidArgumentException('The param $asset type only allow string or array.');
176176
}
177177

@@ -198,7 +198,7 @@ public function dump()
198198
foreach ($assets as $url) {
199199
$url = self::buildUrl(trim($url), $this->baseUrl, $this->getBasePath(), $hostUrl);
200200

201-
$tags[] = $this->assetType === self::TYPE_CSS ? Html::css($url) : Html::script($url);;
201+
$tags[] = $this->assetType === self::TYPE_CSS ? Html::css($url) : Html::script($url);
202202
}
203203

204204
return implode("\n", $tags);
@@ -262,7 +262,7 @@ public function compress(array $options = [])
262262
*/
263263
public function compressAndMerge(array $assets, $saveFile, $webPath = '')
264264
{
265-
$saveDir = dirname($saveFile);
265+
$saveDir = \dirname($saveFile);
266266
$oldKey = '';
267267

268268
// create path.
@@ -342,14 +342,14 @@ public function compressAndSave($url, $saveFile = '', $webPath = '')
342342

343343
// maybe need create directory.
344344
if ($saveFile) {
345-
$saveDir = dirname($saveFile);
345+
$saveDir = \dirname($saveFile);
346346

347347
// create path.
348348
if (!Directory::create($saveDir)) {
349349
throw new FileSystemException("Create dir path [$saveDir] failure!!");
350350
}
351351
} else {
352-
$saveFile = substr($sourceFile, 0, -strlen($this->assetType)) . 'min.' . $this->assetType;
352+
$saveFile = substr($sourceFile, 0, -\strlen($this->assetType)) . 'min.' . $this->assetType;
353353
}
354354

355355
// check target file exists
@@ -454,7 +454,7 @@ public function setAssetType($assetType)
454454
{
455455
$types = [self::TYPE_CSS, self::TYPE_JS];
456456

457-
if (!in_array($assetType, $types, true)) {
457+
if (!\in_array($assetType, $types, true)) {
458458
throw new InvalidArgumentException('param must be is in array(' . implode(',', $types) . ')');
459459
}
460460

libs/Asset/AssetManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected function loggingFileAsset($assets, $type = self::ASSET_CSS_FILE, array
200200
$asset = trim($asset);
201201

202202
// check asset url
203-
if (in_array($type, [self::ASSET_JS_FILE, self::ASSET_CSS_FILE], true)) {
203+
if (\in_array($type, [self::ASSET_JS_FILE, self::ASSET_CSS_FILE], true)) {
204204
$asset = AssetLoad::buildUrl($asset, $this->getBaseUrl(), $this->basePath, false);
205205
}
206206

@@ -267,11 +267,11 @@ protected function checkTypeAndPosition($type, $pos)
267267
$positions = $this->getPositions();
268268
$types = $this->getAssetTypes();
269269

270-
if (!in_array($pos, $positions, true)) {
270+
if (!\in_array($pos, $positions, true)) {
271271
throw new InvalidArgumentException('资源注册位置允许设置 [' . implode(', ', $positions) . '] 中的一个。');
272272
}
273273

274-
if (!in_array($type, $types, true)) {
274+
if (!\in_array($type, $types, true)) {
275275
throw new InvalidArgumentException('资源类型可选 [' . implode(', ', $types) . '] 中的一个。');
276276
}
277277
}
@@ -438,7 +438,7 @@ public function dump($pos = self::POS_HEAD)
438438
{
439439
$assets = $this->getAssetsByPos($pos);
440440

441-
foreach ((array)$assets as $link) {
441+
foreach ($assets as $link) {
442442
echo $link;
443443
}
444444
}

libs/Asset/AssetPublisher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function add($from, $to = '')
121121
return $this;
122122
}
123123

124-
if (is_array($from)) {
124+
if (\is_array($from)) {
125125
array_walk($from, function ($f, $t) {
126126
$this->add($f, $t);
127127
});
@@ -182,8 +182,8 @@ public function publishFile($from, $to, $override = false)
182182
//$targetFile = $to . '/' . basename($from);
183183

184184
if (!file_exists($targetFile) || $override) {
185-
if (!Directory::create(dirname($targetFile), 0775)) {
186-
throw new FileSystemException('Create dir path [' . dirname($targetFile) . '] failure.');
185+
if (!Directory::create(\dirname($targetFile), 0775)) {
186+
throw new FileSystemException('Create dir path [' . \dirname($targetFile) . '] failure.');
187187
}
188188

189189
File::copy($from, $targetFile);
@@ -212,7 +212,7 @@ public function publishDir($fromDir, $toDir, $override = false)
212212

213213
public function hasAssetToPublish()
214214
{
215-
return 0 < count($this->publishAssets['files']) || 0 < count($this->publishAssets['dirs']);
215+
return 0 < \count($this->publishAssets['files']) || 0 < \count($this->publishAssets['dirs']);
216216
}
217217

218218
////////////////////////////// getter/setter method //////////////////////////////

libs/Auth/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function getId()
202202
*/
203203
public function isLogin()
204204
{
205-
return count($this->data) !== 0;
205+
return \count($this->data) !== 0;
206206
}
207207

208208
/**

libs/Env/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ protected function _handleInfo($info)
136136
public function getHeaders()
137137
{
138138
if ($this->_headers === null) {
139-
if (function_exists('getallheaders')) {
139+
if (\function_exists('getallheaders')) {
140140
$this->_headers = getallheaders();
141-
} elseif (function_exists('http_get_request_headers')) {
141+
} elseif (\function_exists('http_get_request_headers')) {
142142
$this->_headers = http_get_request_headers();
143143
} else {
144144
foreach ($_SERVER as $name => $value) {
@@ -182,7 +182,7 @@ protected function _nameConvert($string)
182182
// }
183183

184184
if (strpos($string, 'HTTP_') !== false) {
185-
$string = substr($string, strlen('HTTP_'));
185+
$string = substr($string, \strlen('HTTP_'));
186186
} else {
187187
return false;
188188
}

libs/Env/Server.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getEntry($full = true)
119119
$file = $this->get($key);
120120

121121
if (strpos($file, $wDir) === 0) {
122-
$file = substr($file, strlen($wDir));
122+
$file = substr($file, \strlen($wDir));
123123
}
124124

125125
$file = rtrim($file, '.' . DIRECTORY_SEPARATOR);
@@ -137,7 +137,7 @@ public function getEntry($full = true)
137137
*/
138138
public function getRoot($full = true)
139139
{
140-
return dirname($this->getEntry($full));
140+
return \dirname($this->getEntry($full));
141141
}
142142

143143
/**
@@ -162,7 +162,7 @@ public function isUnix()
162162
{
163163
$uNames = array('CYG', 'DAR', 'FRE', 'HP-', 'IRI', 'LIN', 'NET', 'OPE', 'SUN', 'UNI');
164164

165-
return in_array($this->get('osShort'), $uNames);
165+
return \in_array($this->get('osShort'), $uNames);
166166
}
167167

168168
/**

libs/Files/Captcha.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ public function defaultConfig()
9494
{
9595
return [
9696
// 字体文件
97-
'font' => dirname(__DIR__) . '/resources/fonts/Montserrat-Bold.ttf',
97+
'font' => \dirname(__DIR__) . '/resources/fonts/Montserrat-Bold.ttf',
9898
'randStr' => '23456789abcdefghigkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ',
9999
'width' => '120',
100100
'height' => '45',
101101
'bgColor' => '#eeeeee',
102-
'bgImage' => dirname(__DIR__) . '/resources/images/captcha-bg/06.png',
102+
'bgImage' => \dirname(__DIR__) . '/resources/images/captcha-bg/06.png',
103103
'length' => '4',
104104
'fontColor' => '',
105105
// 验证码字体大小
@@ -175,7 +175,7 @@ public function drawChar()
175175
$captchaStr = '';//保存产生的字符串
176176

177177
for ($i = 0; $i < $this->charNum; $i++) {
178-
$char = $this->codeStr[random_int(0, strlen($this->codeStr) - 1)];
178+
$char = $this->codeStr[random_int(0, \strlen($this->codeStr) - 1)];
179179
$captchaStr .= $char;
180180
$fontColor = imagecolorallocate($this->img, random_int(80, 200), random_int(80, 200), random_int(80, 200));
181181
imagefttext(
@@ -198,7 +198,7 @@ public function drawChar()
198198
public function drawChars()
199199
{
200200
for ($i = 0; $i < $this->fontNum; $i++) {
201-
$char = $this->codeStr[random_int(0, strlen($this->codeStr) - 1)];
201+
$char = $this->codeStr[random_int(0, \strlen($this->codeStr) - 1)];
202202
$fontColor = imagecolorallocate($this->img, random_int(180, 240), random_int(180, 240), random_int(180, 240));
203203
imagefttext(
204204
$this->img, random_int(4, 8), random_int(-30, 40), random_int(8, $this->width - 10),
@@ -288,6 +288,6 @@ public static function verify($captcha)
288288

289289
private function checkGd()
290290
{
291-
return extension_loaded('gd') && function_exists('imagepng');
291+
return \extension_loaded('gd') && \function_exists('imagepng');
292292
}
293293
}

libs/Files/Compress/GzipCompressor.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GzipCompressor extends AbstractCompressor
2525

2626
public function isSupported()
2727
{
28-
return extension_loaded('zlib') && 0 === ini_get('phar.readonly');
28+
return \extension_loaded('zlib') && 0 === ini_get('phar.readonly');
2929
}
3030

3131
/**
@@ -45,7 +45,7 @@ public function encode($sourcePath, $archiveFile, $override = true)
4545
}
4646

4747
// 是一些指定文件
48-
if (is_array($sourcePath)) {
48+
if (\is_array($sourcePath)) {
4949
$files = new \ArrayObject($sourcePath);
5050
} else {
5151
$files = $this->finder->findAll(true, $sourcePath)->getFiles();
@@ -56,8 +56,8 @@ public function encode($sourcePath, $archiveFile, $override = true)
5656
return false;
5757
}
5858

59-
$archiveFile = FileSystem::isAbsPath($archiveFile) ? $archiveFile : dirname($sourcePath) . '/' . $archiveFile;
60-
$archiveFileDir = dirname($archiveFile);
59+
$archiveFile = FileSystem::isAbsPath($archiveFile) ? $archiveFile : \dirname($sourcePath) . '/' . $archiveFile;
60+
$archiveFileDir = \dirname($archiveFile);
6161

6262
FileSystem::mkdir($archiveFileDir);
6363

@@ -99,7 +99,7 @@ public function decode($archiveFile, $extractTo = '', $override = true)
9999
throw new FileNotFoundException('Open the zip file [' . $archiveFile . '] failure!!');
100100
}
101101

102-
$za->extractTo($extractTo ?: dirname($archiveFile));
102+
$za->extractTo($extractTo ?: \dirname($archiveFile));
103103

104104
return $za->close();
105105
}

libs/Files/Compress/ZipCompressor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function encode($sourcePath, $archiveFile, $override = true)
4343
}
4444

4545
// 是一些指定文件
46-
if (is_array($sourcePath)) {
46+
if (\is_array($sourcePath)) {
4747
$files = new \ArrayObject();
4848
} else {
4949
$files = $this->finder->findAll(true, $sourcePath)->getFiles();
@@ -54,9 +54,9 @@ public function encode($sourcePath, $archiveFile, $override = true)
5454
return false;
5555
}
5656

57-
$archiveFile = FileSystem::isAbsPath($archiveFile) ? $archiveFile : dirname($sourcePath) . '/' . $archiveFile;
57+
$archiveFile = FileSystem::isAbsPath($archiveFile) ? $archiveFile : \dirname($sourcePath) . '/' . $archiveFile;
5858

59-
FileSystem::mkdir(dirname($archiveFile));
59+
FileSystem::mkdir(\dirname($archiveFile));
6060

6161
try {
6262
$za = $this->getDriver();
@@ -97,7 +97,7 @@ public function decode($archiveFile, $extractTo = '', $override = true)
9797
throw new FileSystemException('Open the zip file [' . $archiveFile . '] failure!!');
9898
}
9999

100-
$za->extractTo($extractTo ?: dirname($archiveFile));
100+
$za->extractTo($extractTo ?: \dirname($archiveFile));
101101

102102
return $za->close();
103103
}

libs/Files/Picture.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ public static function make(array $waterOptions = [], array $thumbOptions = [])
128128
*/
129129
public function __construct(array $waterOptions = [], array $thumbOptions = [])
130130
{
131-
if (!extension_loaded('gd')) {
131+
if (!\extension_loaded('gd')) {
132132
throw new ExtensionMissException('This tool required extension [gd].');
133133
}
134134

135-
$this->waterOptions['fontFile'] = dirname(__DIR__) . '/resources/fonts/Montserrat-Bold.ttf';
135+
$this->waterOptions['fontFile'] = \dirname(__DIR__) . '/resources/fonts/Montserrat-Bold.ttf';
136136

137137
$this->setWaterOptions($waterOptions)->setThumbOptions($thumbOptions);
138138

@@ -167,7 +167,7 @@ public function watermark($img, $outPath = '', $pos = '', $waterImg = '', $alpha
167167

168168
$imgInfo = pathinfo($img);
169169
$imgType = $this->_handleImageType($imgInfo['extension']);
170-
$outPath = $outPath ?: ($this->waterOptions['path'] ?: dirname($img));
170+
$outPath = $outPath ?: ($this->waterOptions['path'] ?: \dirname($img));
171171
$pos = $pos ?: $this->waterOptions['pos'];
172172
$alpha = $alpha ?: $this->waterOptions['alpha'];
173173
$waterImg = $waterImg ?: $this->waterOptions['img'];
@@ -192,7 +192,7 @@ public function watermark($img, $outPath = '', $pos = '', $waterImg = '', $alpha
192192
}
193193

194194
// create water image resource
195-
$resWaterImg = call_user_func("imagecreatefrom{$waterImgType}", $waterImg);
195+
$resWaterImg = \call_user_func("imagecreatefrom{$waterImgType}", $waterImg);
196196
} else {
197197
//水印文字
198198
$text = $text ?: $this->waterOptions['text'];
@@ -201,7 +201,7 @@ public function watermark($img, $outPath = '', $pos = '', $waterImg = '', $alpha
201201
throw new InvalidConfigException('请配置正确的水印文字资源路径');
202202
}
203203

204-
if (!$text || strlen($this->waterOptions['fontColor']) !== 6) {
204+
if (!$text || \strlen($this->waterOptions['fontColor']) !== 6) {
205205
throw new InvalidConfigException('The watermark font color length must equal to 6.');
206206
}
207207

@@ -251,7 +251,7 @@ public function watermark($img, $outPath = '', $pos = '', $waterImg = '', $alpha
251251
} elseif ($imgType === self::IMAGE_PNG) {
252252
imagepng($resImg, $outFile, ceil($this->waterOptions['quality'] / 10));
253253
} else {
254-
call_user_func("image{$imgType}", $resImg, $outFile);
254+
\call_user_func("image{$imgType}", $resImg, $outFile);
255255
}
256256

257257
imagedestroy($resImg);
@@ -308,7 +308,7 @@ public function thumbnail($img, $outPath = '', $outFilename = '', $thumbWidth =
308308
$thumbType = $thumbType ?: $this->thumbOptions['type'];
309309
$thumbWidth = $thumbWidth ?: $this->thumbOptions['width'];
310310
$thumbHeight = $thumbHeight ?: $this->thumbOptions['height'];
311-
$outPath = $outPath ?: ($this->thumbOptions['path'] ?: dirname($img));
311+
$outPath = $outPath ?: ($this->thumbOptions['path'] ?: \dirname($img));
312312

313313
//获得图像信息
314314
list($imgWidth, $imgHeight) = getimagesize($img);
@@ -319,7 +319,7 @@ public function thumbnail($img, $outPath = '', $outFilename = '', $thumbWidth =
319319

320320
//原始图像资源
321321
// imagecreatefromgif() imagecreatefrompng() imagecreatefromjpeg() imagecreatefromwbmp()
322-
$resImg = call_user_func("imagecreatefrom{$imgType}", $img);
322+
$resImg = \call_user_func("imagecreatefrom{$imgType}", $img);
323323

324324
//缩略图的资源
325325
if ($imgType === static::IMAGE_GIF) {
@@ -333,7 +333,7 @@ public function thumbnail($img, $outPath = '', $outFilename = '', $thumbWidth =
333333
}
334334

335335
// 绘制缩略图X
336-
if (function_exists('imagecopyresampled')) {
336+
if (\function_exists('imagecopyresampled')) {
337337
imagecopyresampled($resThumb, $resImg, 0, 0, 0, 0, $thumbSize[0], $thumbSize[1], $thumbSize[2], $thumbSize[3]);
338338
} else {
339339
imagecopyresized($resThumb, $resImg, 0, 0, 0, 0, $thumbSize[0], $thumbSize[1], $thumbSize[2], $thumbSize[3]);
@@ -350,7 +350,7 @@ public function thumbnail($img, $outPath = '', $outFilename = '', $thumbWidth =
350350
}
351351

352352
// generate image to dst file. imagepng(), imagegif(), imagejpeg(), imagewbmp()
353-
call_user_func("image{$imgType}", $resThumb, $outFile);
353+
\call_user_func("image{$imgType}", $resThumb, $outFile);
354354

355355
imagedestroy($resImg);
356356
imagedestroy($resThumb);
@@ -387,7 +387,7 @@ public static function show($img)
387387
}
388388

389389
/** @var resource $resImg */
390-
$resImg = call_user_func("imagecreatefrom{$type}", $img);
390+
$resImg = \call_user_func("imagecreatefrom{$type}", $img);
391391

392392
// 保持png图片的透明度
393393
if ($type === self::IMAGE_PNG) {
@@ -592,7 +592,7 @@ public static function getImageTypes()
592592
*/
593593
public static function isSupportedType($type)
594594
{
595-
return in_array($type, static::getImageTypes(), true);
595+
return \in_array($type, static::getImageTypes(), true);
596596
}
597597

598598
/**

0 commit comments

Comments
 (0)