Skip to content

Commit

Permalink
bumping travis php versions, composer deps, fixing phpstan errors (#2)
Browse files Browse the repository at this point in the history
* bumping travis php versions, composer deps, fixing phpstan errors

* bumping zend-form version to fix continue errors in php 7.3
  • Loading branch information
jaydiablo authored Feb 19, 2019
1 parent 666cc07 commit fb4fcc4
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 38 deletions.
39 changes: 28 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,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
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand All @@ -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": {
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: 6
configuration: phpstan.neon
phpunit:
metadata:
Expand Down
15 changes: 12 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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, Zend_Captcha_Adapter>\|string given\.#'
- '#Parameter \#2 \$options of method Zend_Form_Element::_getDecorator\(\) expects array\|null, array<string, Zend_Captcha_Adapter>\|string given\.#'
-
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
2 changes: 1 addition & 1 deletion src/Zend/Captcha/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getName();
/**
* Get optional private decorator for this captcha type
*
* @return string
* @return string|null
*/
public function getDecorator();
}
2 changes: 0 additions & 2 deletions src/Zend/Captcha/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
18 changes: 12 additions & 6 deletions src/Zend/Captcha/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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));
}
Expand Down
3 changes: 1 addition & 2 deletions src/Zend/Captcha/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Zend/Form/Element/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/Captcha/FigletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testAdapterElementName()
{
$this->assertEquals(
$this->captcha->getName(),
$this->element->getName()
$this->element->getName()
);
}

Expand All @@ -175,7 +175,7 @@ public function testRenderSetsValue()
$this->testCaptchaIsRendered();
$this->assertEquals(
$this->captcha->getId(),
$this->element->getValue()
$this->element->getValue()
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Zend/Captcha/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -249,7 +249,7 @@ public function testAdapterElementName()
{
$this->assertEquals(
$this->captcha->getName(),
$this->element->getName()
$this->element->getName()
);
}

Expand All @@ -271,7 +271,7 @@ public function testRenderSetsValue()
$this->testCaptchaIsRendered();
$this->assertEquals(
$this->captcha->getId(),
$this->element->getValue()
$this->element->getValue()
);
}

Expand Down

0 comments on commit fb4fcc4

Please sign in to comment.