Skip to content

Commit bf96ae9

Browse files
authored
Merge pull request #15 from JBZoo/feature/refactor-sys
Refactor sys helper
2 parents 005e50b + 58dc450 commit bf96ae9

File tree

12 files changed

+409
-282
lines changed

12 files changed

+409
-282
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ reset:
6666
@echo -e "\033[0;33m>>> >>> >>> >>> >>> >>> >>> >>> \033[0;30;46m Hard reset \033[0m"
6767
@git reset --hard
6868

69+
clean:
70+
@echo -e "\033[0;33m>>> >>> >>> >>> >>> >>> >>> >>> \033[0;30;46m Hard reset \033[0m"
71+
@rm -fr ./build
72+
@mkdir -vp ./build
73+
@rm -fr ./vendor
74+
@rm -vf ./composer.lock
75+
6976
coveralls:
7077
@echo -e "\033[0;33m>>> >>> >>> >>> >>> >>> >>> >>> \033[0;30;46m Send coverage to coveralls.io \033[0m"
7178
@php ./vendor/satooshi/php-coveralls/bin/coveralls --verbose

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"jbzoo/data" : "^1.0"
3030
},
3131
"require-dev" : {
32-
"jbzoo/phpunit" : "^1.6",
32+
"jbzoo/phpunit" : "^1.6|1.x-dev",
3333
"jbzoo/profiler" : "^1.0",
3434
"symfony/process" : "^2.8|^3.1",
3535
"symfony/polyfill-mbstring" : "^1.2"

src/Cli.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public static function exec($command, $args = array(), $cwd = null, $verbose = f
101101

102102
//@codeCoverageIgnoreStart
103103
if ($verbose) {
104-
105104
// Only in testing mode
106105
if (function_exists('\JBZoo\PHPUnit\cliMessage')) {
107106
\JBZoo\PHPUnit\cliMessage('Process: ' . $cmd);
@@ -139,7 +138,6 @@ public static function build($command, $args = array())
139138
$realCommand = $command;
140139

141140
if (count($args) > 0) {
142-
143141
foreach ($args as $key => $value) {
144142
$value = trim($value);
145143
$key = trim($key);
@@ -179,7 +177,6 @@ public static function build($command, $args = array())
179177
public static function hasColorSupport()
180178
{
181179
if (DIRECTORY_SEPARATOR == '\\') {
182-
183180
$winColor = Env::get('ANSICON', Env::VAR_BOOL)
184181
|| 'ON' === Env::get('ConEmuANSI')
185182
|| 'xterm' === Env::get('TERM');

src/Email.php

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,53 +138,50 @@ public static function getDomainSorted(array $emails)
138138
* * If none is defined then a built in default is used. See Email::getGravatarBuiltInDefaultImage().
139139
*
140140
* @param string $email
141-
* @param int $size
141+
* @param int $size
142142
* @param string $defaultImage
143143
* @return null|string
144144
* @link http://en.gravatar.com/site/implement/images/
145145
*/
146-
public static function getGravatarUrl($email, $size = 32, $defaultImage = null)
146+
public static function getGravatarUrl($email, $size = 32, $defaultImage = 'identicon')
147147
{
148148

149149
if (empty($email) || self::_isValid($email) === false) {
150150
return null;
151151
}
152152

153153
$hash = md5(strtolower(trim($email)));
154-
$url = 'http://www.gravatar.com';
155-
$parts = array();
156-
157-
$size = Filter::int($size);
158-
if ($size > 2048) {
159-
$size = 2048;
160-
} elseif ($size < 1) {
161-
$size = 32;
162-
}
163154

155+
$parts = array('scheme' => 'http', 'host' => 'www.gravatar.com');
164156
if (Url::isHttps()) {
165-
$parts = array(
166-
'scheme' => 'https',
167-
'host' => 'secure.gravatar.com'
168-
);
157+
$parts = array('scheme' => 'https', 'host' => 'secure.gravatar.com');
169158
}
170159

171-
$defaultImage = strtolower($defaultImage);
172-
if (preg_match('/(http|https)./', $defaultImage)) {
173-
$defaultImage = urlencode($defaultImage);
174-
} elseif (!(Arr::in((string)$defaultImage, self::getGravatarBuiltInImages()))) {
175-
$defaultImage = self::getGravatarBuiltInDefaultImage();
160+
// Get size
161+
$size = Vars::limit(Filter::int($size), 32, 2048);
162+
163+
// Prepare default images
164+
$defaultImage = trim($defaultImage);
165+
if (preg_match('/^(http|https)./', $defaultImage)) {
166+
$defaultImage = urldecode($defaultImage);
167+
168+
} else {
169+
$defaultImage = strtolower($defaultImage);
170+
if (!(Arr::in((string)$defaultImage, self::getGravatarBuiltInImages()))) {
171+
$defaultImage = self::getGravatarBuiltInDefaultImage();
172+
}
176173
}
177174

178-
return Url::buildAll(
179-
sprintf(
180-
'%s/avatar/%s?s=%d&d=%s',
181-
$url,
182-
$hash,
183-
$size,
184-
$defaultImage
185-
),
186-
$parts
175+
// Build full url
176+
$parts['path'] = '/avatar/' . $hash . '/';
177+
$parts['query'] = array(
178+
's' => $size,
179+
'd' => $defaultImage,
187180
);
181+
182+
$url = Url::create($parts);
183+
184+
return $url;
188185
}
189186

190187
/**

src/Env.php

Lines changed: 20 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -28,185 +28,93 @@ class Env
2828
const VAR_STRING = 16;
2929

3030
/**
31-
* @var string
32-
*/
33-
private static $_binary;
34-
35-
/**
36-
* Returns true when Xdebug is supported or
37-
* the runtime used is PHPDBG (PHP >= 7.0).
38-
*
39-
* @return bool
40-
*/
41-
public static function canCollectCodeCoverage()
42-
{
43-
return self::hasXdebug() || self::hasPHPDBGCodeCoverage();
44-
}
45-
46-
/**
47-
* Returns the path to the binary of the current runtime.
48-
* Appends ' --php' to the path when the runtime is HHVM.
49-
*
5031
* @return string
51-
*
52-
* @SuppressWarnings(PHPMD.NPathComplexity)
53-
* @SuppressWarnings(PHPMD.Superglobals)
54-
* @codeCoverageIgnore
32+
* @deprecated
5533
*/
5634
public static function getBinary()
5735
{
58-
// HHVM
59-
if (self::$_binary === null && self::isHHVM()) {
60-
if ((self::$_binary = getenv('PHP_BINARY')) === false) {
61-
self::$_binary = PHP_BINARY;
62-
}
63-
self::$_binary = escapeshellarg(self::$_binary) . ' --php';
64-
}
65-
66-
// PHP >= 5.4.0
67-
if (self::$_binary === null && defined('PHP_BINARY')) {
68-
self::$_binary = escapeshellarg(PHP_BINARY);
69-
}
70-
71-
// PHP < 5.4.0
72-
if (self::$_binary === null) {
73-
if (PHP_SAPI == 'cli' && isset($_SERVER['_'])) {
74-
if (strpos($_SERVER['_'], 'phpunit') !== false) {
75-
$file = file($_SERVER['_']);
76-
77-
if (strpos($file[0], ' ') !== false) {
78-
$tmp = explode(' ', $file[0]);
79-
self::$_binary = escapeshellarg(trim($tmp[1]));
80-
} else {
81-
self::$_binary = escapeshellarg(ltrim(trim($file[0]), '#!'));
82-
}
83-
84-
} elseif (strpos(basename($_SERVER['_']), 'php') !== false) {
85-
self::$_binary = escapeshellarg($_SERVER['_']);
86-
}
87-
}
88-
}
89-
90-
if (self::$_binary === null) {
91-
$binaryLocations = array(
92-
PHP_BINDIR . '/php',
93-
PHP_BINDIR . '/php-cli.exe',
94-
PHP_BINDIR . '/php.exe',
95-
);
96-
97-
foreach ($binaryLocations as $binary) {
98-
if (is_readable($binary)) {
99-
self::$_binary = escapeshellarg($binary);
100-
break;
101-
}
102-
}
103-
}
104-
105-
if (self::$_binary === null) {
106-
self::$_binary = 'php';
107-
}
108-
109-
return self::$_binary;
36+
return Sys::getBinary();
11037
}
11138

11239
/**
11340
* @return string
41+
* @deprecated
11442
*/
11543
public static function getNameWithVersion()
11644
{
117-
return self::getName() . ' ' . self::getVersion();
45+
return Sys::getNameWithVersion();
11846
}
11947

12048
/**
12149
* @return string
50+
* @deprecated
12251
*/
12352
public static function getName()
12453
{
125-
if (self::isHHVM()) {
126-
return 'HHVM';
127-
128-
} elseif (self::isPHPDBG()) {
129-
return 'PHPDBG';
130-
}
131-
132-
return 'PHP';
54+
return Sys::getName();
13355
}
13456

13557
/**
13658
* @return string
59+
* @deprecated
13760
*/
13861
public static function getVendorUrl()
13962
{
140-
if (self::isHHVM()) {
141-
return 'http://hhvm.com/';
142-
} else {
143-
return 'http://php.net/';
144-
}
63+
return Sys::getVendorUrl();
14564
}
14665

14766
/**
14867
* @return string
68+
* @deprecated
14969
*/
15070
public static function getVersion()
15171
{
152-
if (self::isHHVM()) {
153-
return HHVM_VERSION;
154-
} else {
155-
return PHP_VERSION;
156-
}
72+
return Sys::getVersion();
15773
}
15874

15975
/**
160-
* Returns true when the runtime used is PHP and Xdebug is loaded.
161-
*
16276
* @return bool
77+
* @deprecated
16378
*/
16479
public static function hasXdebug()
16580
{
166-
return (self::isPHP() || self::isHHVM()) && extension_loaded('xdebug');
81+
return Sys::hasXdebug();
16782
}
16883

16984
/**
170-
* Returns true when the runtime used is HHVM.
171-
*
17285
* @return bool
86+
* @deprecated
17387
*/
17488
public static function isHHVM()
17589
{
176-
return defined('HHVM_VERSION');
90+
return Sys::isHHVM();
17791
}
17892

17993
/**
180-
* Returns true when the runtime used is PHP without the PHPDBG SAPI.
181-
*
18294
* @return bool
95+
* @deprecated
18396
*/
18497
public static function isPHP()
18598
{
186-
return !self::isHHVM() && !self::isPHPDBG();
99+
return Sys::isRealPHP();
187100
}
188101

189102
/**
190-
* Returns true when the runtime used is PHP with the PHPDBG SAPI.
191-
*
192103
* @return bool
193-
* @codeCoverageIgnore
104+
* @deprecated
194105
*/
195106
public static function isPHPDBG()
196107
{
197-
return PHP_SAPI === 'phpdbg' && !self::isHHVM();
108+
return Sys::isPHPDBG();
198109
}
199110

200111
/**
201-
* Returns true when the runtime used is PHP with the PHPDBG SAPI
202-
* and the phpdbg_*_oplog() functions are available (PHP >= 7.0).
203-
*
204112
* @return bool
205-
* @codeCoverageIgnore
113+
* @deprecated
206114
*/
207115
public static function hasPHPDBGCodeCoverage()
208116
{
209-
return self::isPHPDBG() && function_exists('phpdbg_start_oplog');
117+
return Sys::hasPHPDBGCodeCoverage();
210118
}
211119

212120
/**

src/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public static function esc($string)
370370

371371
/**
372372
* @param array|Data $data
373-
* @return JSON
373+
* @return Data
374374
*/
375375
public static function data($data)
376376
{

src/Str.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ public static function esc($string)
655655
*
656656
* @param string $input
657657
* @param string $separator
658+
* @param bool $toLower*
658659
* @return string
659660
*/
660661
public static function splitCamelCase($input, $separator = '_', $toLower = true)

0 commit comments

Comments
 (0)