From fb4fcc4aedca969d0b7397a2de405983f0f7d928 Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Tue, 19 Feb 2019 15:52:32 -0700 Subject: [PATCH] bumping travis php versions, composer deps, fixing phpstan errors (#2) * bumping travis php versions, composer deps, fixing phpstan errors * bumping zend-form version to fix continue errors in php 7.3 --- .travis.yml | 39 ++++++++++++++++++++++--------- composer.json | 10 ++++---- grumphp.yml.dist | 1 - phpstan.neon | 15 +++++++++--- src/Zend/Captcha/Adapter.php | 2 +- src/Zend/Captcha/Base.php | 2 -- src/Zend/Captcha/Image.php | 18 +++++++++----- src/Zend/Captcha/Word.php | 3 +-- src/Zend/Form/Element/Captcha.php | 4 ++-- tests/Zend/Captcha/FigletTest.php | 4 ++-- tests/Zend/Captcha/ImageTest.php | 6 ++--- 11 files changed, 66 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index da5bcd7..1016462 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,13 +2,9 @@ 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: @@ -16,7 +12,7 @@ branches: install: - phpenv rehash - - travis_retry composer install --no-interaction --prefer-source + - travis_retry composer update --no-interaction --prefer-source $COMPOSER_ARGS stages: - test @@ -33,20 +29,41 @@ 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=962f1e938139e47bbd21e94d011fde55c0b588620267ed1ad19fb54f803b00ca before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter diff --git a/composer.json b/composer.json index fe863a3..10c3cbc 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "diablomedia/zendframework1-loader": "^1.0.0", "diablomedia/zendframework1-crypt": "^1.0.0", "diablomedia/zendframework1-text": "^1.0.0", - "diablomedia/zendframework1-form": "^1.0.0", + "diablomedia/zendframework1-form": "^1.0.2", "diablomedia/zendframework1-service-recaptcha": "^1.0.0", "diablomedia/zendframework1-session": "^1.0.0", "diablomedia/zendframework1-validate": "^1.0.0", @@ -36,10 +36,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": [ @@ -51,7 +51,7 @@ "scripts": { "test": "phpunit", "test-with-coverage": "phpunit --coverage-clover=clover.xml", - "phpstan": "phpstan analyze -l6 -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": { diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 62f4101..0dbe337 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -9,7 +9,6 @@ parameters: allow_risky: true config: .php_cs phpstan: - level: 6 configuration: phpstan.neon phpunit: metadata: diff --git a/phpstan.neon b/phpstan.neon index 06434fb..9d9de0a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,12 +1,21 @@ parameters: + level: 6 + paths: + - ./ excludes_analyse: - %rootDir%/../../../vendor/* - %rootDir%/../../../tests/* ignoreErrors: - - '#Casting to int something that.s already int\.#' - '#Access to an undefined property Zend_Session_Namespace::\$word\.#' - '#Call to an undefined method Zend_View_Abstract::doctype\(\)\.#' - '#Call to an undefined method Zend_View_Interface::.+\(\)\.#' - '#Call to an undefined method Zend_Form\|Zend_Form_DisplayGroup\|Zend_Form_Element::get.+\(\)\.#' - - '#Parameter \#1 \$name of method Zend_Form_Element::_getDecorator\(\) expects string, array\|string given\.#' - - '#Parameter \#2 \$options of method Zend_Form_Element::_getDecorator\(\) expects array\|null, array\|string given\.#' \ No newline at end of file + - + message: '#Left side of && is always true\.#' + path: %currentWorkingDirectory%/src/Zend/Captcha/Image.php + - + message: '#Negated boolean expression is always false\.#' + path: %currentWorkingDirectory%/src/Zend/Captcha/ReCaptcha.php + - + message: '#If condition is always true\.#' + path: %currentWorkingDirectory%/src/Zend/Captcha/Word.php diff --git a/src/Zend/Captcha/Adapter.php b/src/Zend/Captcha/Adapter.php index 6c2cfb2..6fac03b 100644 --- a/src/Zend/Captcha/Adapter.php +++ b/src/Zend/Captcha/Adapter.php @@ -67,7 +67,7 @@ public function getName(); /** * Get optional private decorator for this captcha type * - * @return string + * @return string|null */ public function getDecorator(); } diff --git a/src/Zend/Captcha/Base.php b/src/Zend/Captcha/Base.php index 29108ee..c356b14 100644 --- a/src/Zend/Captcha/Base.php +++ b/src/Zend/Captcha/Base.php @@ -160,8 +160,6 @@ public function setConfig(Zend_Config $config) * Get optional decorator * * By default, return null, indicating no extra decorator needed. - * - * @return null */ public function getDecorator() { diff --git a/src/Zend/Captcha/Image.php b/src/Zend/Captcha/Image.php index f2a9a15..8d091dc 100644 --- a/src/Zend/Captcha/Image.php +++ b/src/Zend/Captcha/Image.php @@ -484,6 +484,9 @@ protected function _generateImage($id, $word) $img_file = $this->getImgDir() . $id . $this->getSuffix(); if (empty($this->_startImage)) { $img = imagecreatetruecolor($w, $h); + if (!$img) { + throw new Zend_Captcha_Exception('Can not load start image'); + } } else { $img = imagecreatefrompng($this->_startImage); if (!$img) { @@ -496,8 +499,8 @@ protected function _generateImage($id, $word) $bg_color = imagecolorallocate($img, 255, 255, 255); imagefilledrectangle($img, 0, 0, $w - 1, $h - 1, $bg_color); $textbox = imageftbbox($fsize, 0, $font, $word); - $x = ($w - ($textbox[2] - $textbox[0])) / 2; - $y = ($h - ($textbox[7] - $textbox[1])) / 2; + $x = (int) ($w - ($textbox[2] - $textbox[0])) / 2; + $y = (int) ($h - ($textbox[7] - $textbox[1])) / 2; imagefttext($img, $fsize, 0, $x, $y, $text_color, $font, $word); // generate noise @@ -510,6 +513,9 @@ protected function _generateImage($id, $word) // transformed image $img2 = imagecreatetruecolor($w, $h); + if (!$img2) { + throw new Zend_Captcha_Exception('Can not load transformed image'); + } $bg_color = imagecolorallocate($img2, 255, 255, 255); imagefilledrectangle($img2, 0, 0, $w - 1, $h - 1, $bg_color); // apply wave transforms @@ -528,8 +534,8 @@ protected function _generateImage($id, $word) for ($x = 0; $x < $w; $x++) { for ($y = 0; $y < $h; $y++) { - $sx = $x + (sin($x * $freq1 + $ph1) + sin($y * $freq3 + $ph3)) * $szx; - $sy = $y + (sin($x * $freq2 + $ph2) + sin($y * $freq4 + $ph4)) * $szy; + $sx = (int) ($x + (sin($x * $freq1 + $ph1) + sin($y * $freq3 + $ph3)) * $szx); + $sy = (int) ($y + (sin($x * $freq2 + $ph2) + sin($y * $freq4 + $ph4)) * $szy); if ($sx < 0 || $sy < 0 || $sx >= $w - 1 || $sy >= $h - 1) { continue; @@ -552,10 +558,10 @@ protected function _generateImage($id, $word) $frac_x1 = 1 - $frac_x; $frac_y1 = 1 - $frac_y; - $newcolor = $color * $frac_x1 * $frac_y1 + $newcolor = (int) ($color * $frac_x1 * $frac_y1 + $color_x * $frac_x * $frac_y1 + $color_y * $frac_x1 * $frac_y - + $color_xy * $frac_x * $frac_y; + + $color_xy * $frac_x * $frac_y); } imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newcolor, $newcolor, $newcolor)); } diff --git a/src/Zend/Captcha/Word.php b/src/Zend/Captcha/Word.php index edc4f2f..178e80c 100644 --- a/src/Zend/Captcha/Word.php +++ b/src/Zend/Captcha/Word.php @@ -270,7 +270,6 @@ public function getSession() /** * Set session namespace object * - * @param Zend_Session_Namespace $session * @return $this */ public function setSession(Zend_Session_Namespace $session) @@ -357,7 +356,7 @@ public function generate() protected function _generateRandomId() { - return md5(Zend_Crypt_Math::randBytes(32)); + return md5((string) Zend_Crypt_Math::randBytes(32)); } /** diff --git a/src/Zend/Form/Element/Captcha.php b/src/Zend/Form/Element/Captcha.php index 6c5d8dc..ad70582 100644 --- a/src/Zend/Form/Element/Captcha.php +++ b/src/Zend/Form/Element/Captcha.php @@ -276,8 +276,8 @@ public function isValid($value, $context = null) } $name = $this->getFullyQualifiedName(); - $root = substr($name, 0, strpos($name, '[')); - $segments = substr($name, strpos($name, '[')); + $root = substr($name, 0, (int) strpos($name, '[')); + $segments = substr($name, (int) strpos($name, '[')); $segments = ltrim($segments, '['); $segments = rtrim($segments, ']'); $segments = explode('][', $segments); diff --git a/tests/Zend/Captcha/FigletTest.php b/tests/Zend/Captcha/FigletTest.php index c026be0..84a898a 100644 --- a/tests/Zend/Captcha/FigletTest.php +++ b/tests/Zend/Captcha/FigletTest.php @@ -153,7 +153,7 @@ public function testAdapterElementName() { $this->assertEquals( $this->captcha->getName(), - $this->element->getName() + $this->element->getName() ); } @@ -175,7 +175,7 @@ public function testRenderSetsValue() $this->testCaptchaIsRendered(); $this->assertEquals( $this->captcha->getId(), - $this->element->getValue() + $this->element->getValue() ); } diff --git a/tests/Zend/Captcha/ImageTest.php b/tests/Zend/Captcha/ImageTest.php index 29f1026..05e472b 100644 --- a/tests/Zend/Captcha/ImageTest.php +++ b/tests/Zend/Captcha/ImageTest.php @@ -61,7 +61,7 @@ public function setUp() } $this->element = new Zend_Form_Element_Captcha( 'captchaI', - array('captcha' => array('Image', + array('captcha' => array('Image', 'sessionClass' => 'Zend_Captcha_ImageTest_SessionContainer', 'imgDir' => $this->testDir, 'font' => dirname(__FILE__) . '/../Pdf/_fonts/Vera.ttf') @@ -249,7 +249,7 @@ public function testAdapterElementName() { $this->assertEquals( $this->captcha->getName(), - $this->element->getName() + $this->element->getName() ); } @@ -271,7 +271,7 @@ public function testRenderSetsValue() $this->testCaptchaIsRendered(); $this->assertEquals( $this->captcha->getId(), - $this->element->getValue() + $this->element->getValue() ); }