Skip to content

Commit

Permalink
bumping travis php versions, composer deps, fixing phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydiablo committed Mar 1, 2019
1 parent a30ecfb commit 2aa3da4
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 53 deletions.
37 changes: 26 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ language: php

sudo: false

php:
- 7
- 7.1
- 7.2
- nightly

env: TMPDIR=/tmp USE_XDEBUG=false
env:
global:
- COMPOSER_ARGS="" TMPDIR=/tmp USE_XDEBUG=false

branches:
only:
master

install:
- phpenv rehash
- travis_retry composer install --no-interaction --prefer-source
- travis_retry composer update --no-interaction --prefer-source $COMPOSER_ARGS

stages:
- test
Expand All @@ -33,20 +29,39 @@ script:
jobs:
fast_finish: true
allow_failures:
- php: 7.4snapshot
- php: nightly
include:
- php: 7.1
env: COMPOSER_ARGS="--prefer-lowest"
- php: 7.1
- php: 7.2
env: COMPOSER_ARGS="--prefer-lowest"
- php: 7.2
- php: 7.3
env: COMPOSER_ARGS="--prefer-lowest"
- php: 7.3
- php: 7.4snapshot
env: COMPOSER_ARGS="--ignore-platform-reqs --prefer-lowest"
- php: 7.4snapshot
env: COMPOSER_ARGS="--ignore-platform-reqs"
- php: nightly
env: COMPOSER_ARGS="--ignore-platform-reqs --prefer-lowest"
- php: nightly
env: COMPOSER_ARGS="--ignore-platform-reqs"

- stage: style check
php: 7.1
php: 7.2
env: TMPDIR=/tmp USE_XDEBUG=false
script:
- composer style-check
- stage: phpstan analysis
php: 7.1
php: 7.2
env: TMPDIR=/tmp USE_XDEBUG=false
script:
- composer phpstan
- stage: test with coverage
php: 7.1
php: 7.2
env: TMPDIR=/tmp USE_XDEBUG=true CC_TEST_REPORTER_ID=b2ab6481229cda30d587c3d822cf597ba58e8f9fca97f3f6eea94b467a09d225
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
}
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpstan/phpstan": "^0.9.2",
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.11.2",
"friendsofphp/php-cs-fixer": "^2.11",
"maglnet/composer-require-checker": "^0.1.6 | ^0.2.1",
"maglnet/composer-require-checker": "^1.1.0",
"phpro/grumphp": "^0.14.0"
},
"include-path": [
Expand All @@ -43,7 +43,7 @@
"scripts": {
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -l7 -c phpstan.neon --no-progress ./ --ansi",
"phpstan": "phpstan analyze -c phpstan.neon --no-progress --ansi",
"style-check": "php-cs-fixer fix --dry-run -vv"
},
"suggest": {
Expand Down
1 change: 0 additions & 1 deletion grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ parameters:
allow_risky: true
config: .php_cs
phpstan:
level: 7
configuration: phpstan.neon
phpunit:
metadata:
Expand Down
17 changes: 16 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
parameters:
level: 7
paths:
- ./
excludes_analyse:
- %rootDir%/../../../vendor/*
- %rootDir%/../../../tests/*
ignoreErrors:
- '#Casting to .+ something that.s already .+\.#'
- '#Variable \$padMode might not be defined\.#'
# Defensive coding
-
message: '#Strict comparison using === between true and false will always evaluate to false\.#'
path: %currentWorkingDirectory%/src/Zend/Text/Table/Column.php
-
message: '#Strict comparison using === between int and false will always evaluate to false\.#'
path: %currentWorkingDirectory%/src/Zend/Text/Figlet.php
-
message: '#Strict comparison using === between int and null will always evaluate to false\.#'
path: %currentWorkingDirectory%/src/Zend/Text/MultiByte.php
-
message: '#Result of && is always false\.#'
path: %currentWorkingDirectory%/src/Zend/Text/Table.php
38 changes: 19 additions & 19 deletions src/Zend/Text/Figlet.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,33 +444,33 @@ public function render($text, $encoding = 'UTF-8')

$wordBreakMode = 0;
$lastCharWasEol = false;
$textLength = @iconv_strlen($text, 'UTF-8');
$textLength = @iconv_strlen((string) $text, 'UTF-8');

if ($textLength === false) {
throw new Zend_Text_Figlet_Exception('$text is not encoded with ' . $encoding);
}

for ($charNum = 0; $charNum < $textLength; $charNum++) {
// Handle paragraphs
$char = iconv_substr($text, $charNum, 1, 'UTF-8');
$char = iconv_substr((string) $text, $charNum, 1, 'UTF-8');

if ($char === "\n" && $this->_handleParagraphs && !$lastCharWasEol) {
$nextChar = iconv_substr($text, ($charNum + 1), 1, 'UTF-8');
$nextChar = iconv_substr((string) $text, ($charNum + 1), 1, 'UTF-8');
if (!$nextChar) {
$nextChar = null;
}

$char = (ctype_space($nextChar)) ? "\n" : ' ';
$char = (ctype_space((string) $nextChar)) ? "\n" : ' ';
}

$lastCharWasEol = (ctype_space($char) && $char !== "\t" && $char !== ' ');
$lastCharWasEol = (ctype_space((string) $char) && $char !== "\t" && $char !== ' ');

if (ctype_space($char)) {
if (ctype_space((string) $char)) {
$char = ($char === "\t" || $char === ' ') ? ' ': "\n";
}

// Skip unprintable characters
$ordChar = $this->_uniOrd($char);
$ordChar = $this->_uniOrd((string) $char);
if (($ordChar > 0 && $ordChar < 32 && $char !== "\n") || $ordChar === 127) {
continue;
}
Expand All @@ -495,7 +495,7 @@ public function render($text, $encoding = 'UTF-8')
if ($char === "\n") {
$this->_appendLine();
$wordBreakMode = false;
} elseif ($this->_addChar($char)) {
} elseif ($this->_addChar((string) $char)) {
if ($char !== ' ') {
$wordBreakMode = ($wordBreakMode >= 2) ? 3: 1;
} else {
Expand Down Expand Up @@ -1001,15 +1001,15 @@ protected function _loadFont($fontFile)

// Get the header
$numsRead = sscanf(
fgets($fp, 1000),
'%*c%c %d %*d %d %d %d %d %d',
$this->_hardBlank,
$this->_charHeight,
$this->_maxLength,
$smush,
$cmtLines,
$rightToLeft,
$this->_fontSmush
(string) fgets($fp, 1000),
'%*c%c %d %*d %d %d %d %d %d',
$this->_hardBlank,
$this->_charHeight,
$this->_maxLength,
$smush,
$cmtLines,
$rightToLeft,
$this->_fontSmush
);

if ($magic !== self::FONTFILE_MAGIC_NUMBER || $numsRead < 5) {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ protected function _loadFont($fontFile)
// At the end fetch all extended characters
while (!feof($fp)) {
// Get the Unicode
list($uniCode) = explode(' ', fgets($fp, 2048));
list($uniCode) = explode(' ', (string) fgets($fp, 2048));

if (empty($uniCode)) {
continue;
Expand Down Expand Up @@ -1189,7 +1189,7 @@ protected function _loadChar($fp)
return false;
}

$line = rtrim(fgets($fp, 2048), "\r\n");
$line = rtrim((string) fgets($fp, 2048), "\r\n");

if (preg_match('#(.)\\1?$#', $line, $result) === 1) {
$line = str_replace($result[1], '', $line);
Expand Down
6 changes: 3 additions & 3 deletions src/Zend/Text/MultiByte.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ public static function strPad($input, $padLength, $padString = ' ', $padType = S
if ($padStringLength === 0 || $lengthOfPadding <= 0) {
$return = $input;
} else {
$repeatCount = floor($lengthOfPadding / $padStringLength);
$repeatCount = (int) floor($lengthOfPadding / $padStringLength);

if ($padType === STR_PAD_BOTH) {
$lastStringLeft = '';
$lastStringRight = '';
$repeatCountLeft = $repeatCountRight = ($repeatCount - $repeatCount % 2) / 2;
$repeatCountLeft = $repeatCountRight = (int) ($repeatCount - $repeatCount % 2) / 2;

$lastStringLength = $lengthOfPadding - 2 * $repeatCountLeft * $padStringLength;
$lastStringLeftLength = $lastStringRightLength = floor($lastStringLength / 2);
$lastStringLeftLength = $lastStringRightLength = (int) floor($lastStringLength / 2);
$lastStringRightLength += $lastStringLength % 2;

$lastStringLeft = iconv_substr($padString, 0, $lastStringLeftLength, $charset);
Expand Down
8 changes: 4 additions & 4 deletions src/Zend/Text/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function render()
foreach ($columnWidths as $columnNum => $columnWidth) {
$result .= str_repeat(
$this->_decorator->getHorizontal(),
$columnWidth
$columnWidth
);

if (($columnNum + 1) === $numColumns) {
Expand Down Expand Up @@ -431,7 +431,7 @@ public function render()
// Add the horizontal line
$result .= str_repeat(
$this->_decorator->getHorizontal(),
$columnWidth
$columnWidth
);

// If this is the last line, break out
Expand Down Expand Up @@ -491,13 +491,13 @@ public function render()
$result .= $renderedRow;

// If this is the last row, draw the table bottom
if (($rowNum + 1) === $numRows) {
if (((int) $rowNum + 1) === $numRows) {
$result .= $this->_decorator->getBottomLeft();

foreach ($columnWidths as $columnNum => $columnWidth) {
$result .= str_repeat(
$this->_decorator->getHorizontal(),
$columnWidth
$columnWidth
);

if (($columnNum + 1) === $numColumns) {
Expand Down
6 changes: 3 additions & 3 deletions src/Zend/Text/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function setContent($content, $charset = null)
if ($inputCharset !== $outputCharset) {
if (PHP_OS !== 'AIX') {
// AIX does not understand these character sets
$content = iconv($inputCharset, $outputCharset, $content);
$content = (string) iconv($inputCharset, $outputCharset, $content);
}
}

Expand Down Expand Up @@ -152,7 +152,7 @@ public function setAlign($align)
*/
public function setColSpan($colSpan)
{
if (is_int($colSpan) === false or $colSpan < 1) {
if (is_int($colSpan) === false || $colSpan < 1) {
throw new Zend_Text_Table_Exception('$colSpan must be an integer and greater than 0');
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public function getColSpan()
*/
public function render($columnWidth, $padding = 0)
{
if (is_int($columnWidth) === false or $columnWidth < 1) {
if (is_int($columnWidth) === false || $columnWidth < 1) {
throw new Zend_Text_Table_Exception('$columnWidth must be an integer and greater than 0');
}

Expand Down
14 changes: 7 additions & 7 deletions src/Zend/Text/Table/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public function getColumnWidths()
*/
public function render(
array $columnWidths,
Zend_Text_Table_Decorator_Interface $decorator,
$padding = 0
Zend_Text_Table_Decorator_Interface $decorator,
$padding = 0
) {
// Prepare an array to store all column widths
$this->_columnWidths = array();
Expand All @@ -162,8 +162,8 @@ public function render(
// Calculate the column width
$columnWidth = ($colSpan - 1 + array_sum(array_slice(
$columnWidths,
$colNum,
$colSpan
(int) $colNum,
$colSpan
)));

// Render the column and split it's lines into an array
Expand All @@ -186,9 +186,9 @@ public function render(
$remainingWidth = (count($columnWidths) - $colNum - 1) +
array_sum(array_slice(
$columnWidths,
$colNum
(int) $colNum
));
$renderedColumns[] = array(str_repeat(' ', $remainingWidth));
$renderedColumns[] = array(str_repeat(' ', (int) $remainingWidth));

$this->_columnWidths[] = $remainingWidth;
}
Expand All @@ -202,7 +202,7 @@ public function render(
if (isset($renderedColumn[$line]) === true) {
$result .= $renderedColumn[$line];
} else {
$result .= str_repeat(' ', $this->_columnWidths[$index]);
$result .= str_repeat(' ', (int) $this->_columnWidths[$index]);
}

$result .= $decorator->getVertical();
Expand Down

0 comments on commit 2aa3da4

Please sign in to comment.