Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 - Replace intval() with int typecasts #4584

Merged
merged 2 commits into from
Sep 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Cache/Engine/ApcEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function read($key) {
$key = $this->_key($key);

$time = time();
$cachetime = intval(apc_fetch($key . '_expires'));
$cachetime = (int)apc_fetch($key . '_expires');
if ($cachetime !== 0 && ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Engine/FileEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function read($key) {

$this->_File->rewind();
$time = time();
$cachetime = intval($this->_File->current());
$cachetime = (int)$this->_File->current();

if ($cachetime !== false &&
($cachetime < $time || ($time + $this->_config['duration']) < $cachetime)
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Engine/WincacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function read($key) {
$key = $this->_key($key);

$time = time();
$cachetime = intval(wincache_ucache_get($key . '_expires'));
$cachetime = (int)wincache_ucache_get($key . '_expires');
if ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Engine/XcacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function read($key) {

if (xcache_isset($key)) {
$time = time();
$cachetime = intval(xcache_get($key . '_expires'));
$cachetime = (int)xcache_get($key . '_expires');
if ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/PaginatorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function paginate($object, array $settings = []) {
$options = $this->checkLimit($options);

$options += ['page' => 1];
$options['page'] = intval($options['page']) < 1 ? 1 : (int)$options['page'];
$options['page'] = (int)$options['page'] < 1 ? 1 : (int)$options['page'];
list($finder, $options) = $this->_extractFinder($options);

if (empty($query)) {
Expand All @@ -171,7 +171,7 @@ public function paginate($object, array $settings = []) {

$page = $options['page'];
$limit = $options['limit'];
$pageCount = intval(ceil($count / $limit));
$pageCount = (int)ceil($count / $limit);
$requestedPage = $page;
$page = max(min($page, $pageCount), 1);
$request = $this->_registry->getController()->request;
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Type/IntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function toDatabase($value, Driver $driver) {
if ($value === null || $value === '') {
return null;
}
return intval($value);
return (int)$value;
}

/**
Expand All @@ -51,7 +51,7 @@ public function toPHP($value, Driver $driver) {
if ($value === null) {
return null;
}
return intval($value);
return (int)$value;
}

/**
Expand All @@ -75,7 +75,7 @@ public function marshal($value) {
if ($value === null || $value === '') {
return null;
}
return intval($value);
return (int)$value;
}

}
2 changes: 1 addition & 1 deletion src/Shell/Task/PluginTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public function findPath(array $pathOptions) {
}
$prompt = 'Choose a plugin path from the paths above.';
$choice = $this->in($prompt, null, 1);
if (intval($choice) > 0 && intval($choice) <= $max) {
if ((int)$choice > 0 && (int)$choice <= $max) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pico-optimization; $choice = (int)$this->in($prompt, null, 1); instead of doing it twice inside the if(..

$valid = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utility/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ protected static function _simpleOp($op, $data, $path, $values = null) {
$count = count($path);
$last = $count - 1;
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
$key = intval($key);
if (is_numeric($key) && (int)$key > 0 || $key === '0') {
$key = (int)$key;
}
if ($op === 'insert') {
if ($i === $last) {
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/PaginatorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public function numbers(array $options = array()) {
$ellipsis = $templater->format('ellipsis', []);

if ($options['modulus'] && $params['pageCount'] > $options['modulus']) {
$half = intval($options['modulus'] / 2);
$half = (int)($options['modulus'] / 2);
$end = $params['page'] + $half;

if ($end > $params['pageCount']) {
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Error/DebuggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function testChangeOutputFormats() {
'error' => array(),
'code' => array(), '8', '/code',
'file' => array(), 'preg:/[^<]+/', '/file',
'line' => array(), '' . (intval(__LINE__) - 7), '/line',
'line' => array(), '' . (int)__LINE__ - 7, '/line',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think a cast is required at all; __LINE__ already is an integer (var_dump(__LINE__); // int 2), however, possibly wrap the calculation in parentheses (__LINE__ - 7) because of the concatenation; alternatively cast the result to a string, instead of the concatenation, if that is the intention ((string)(__LINE__ - 7)) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. This could be done without casting but with () wrapping.
The string cast is not necessary as the concatination automatically casts :)

'preg:/Undefined variable:\s+foo/',
'/error'
);
Expand Down Expand Up @@ -259,7 +259,7 @@ public function testAddFormat() {
'<error',
'<code', '8', '/code',
'<file', 'preg:/[^<]+/', '/file',
'<line', '' . (intval(__LINE__) - 7), '/line',
'<line', '' . (int)__LINE__ - 7, '/line',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

'preg:/Undefined variable:\s+foo/',
'/error'
);
Expand Down