Skip to content

Commit c2741ab

Browse files
authored
Merge pull request #17 from Oefenweb/cs-fixes
URL changes from HTTP to HTTPS
2 parents 1bc2496 + 08d848d commit c2741ab

File tree

18 files changed

+195
-140
lines changed

18 files changed

+195
-140
lines changed

.travis.yml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,36 @@ language: php
33
sudo: false
44

55
php:
6-
- 7.0
76
- 7.1
7+
- 7.2
8+
- 7.3
9+
- 7.4
810

911
env:
1012
global:
11-
- CAKE_VERSION=^3.0.0
12-
13-
matrix:
14-
- CAKE_VERSION=~3.4.0
15-
- CAKE_VERSION=~3.5.0
13+
- CAKE_VERSION=^3.8.0
1614

1715
matrix:
1816
include:
19-
- php: 7.1
17+
- php: 7.2
2018
env:
2119
- PHP_SYNTAX=1
22-
- php: 7.1
20+
- php: 7.2
2321
env:
2422
- PHP_CS=1
25-
- php: 7.1
23+
- php: 7.2
2624
env:
2725
- PHP_CPD=1
28-
- php: 7.1
26+
- php: 7.2
2927
env:
3028
- PHP_MD=1
31-
- php: 7.1
29+
- php: 7.2
30+
env:
31+
- PHP_STAN=1
32+
- php: 7.2
33+
env:
34+
- PHP_PHAN=1
35+
- php: 7.2
3236
env:
3337
- PHP_COVERAGE=1
3438

@@ -39,16 +43,10 @@ branches:
3943
- 3.x
4044

4145
before_script:
42-
- travis_wait ./.travis/before-script.sh
46+
- ./.travis/before-script.sh
4347

4448
script:
4549
- ./.travis/script.sh
4650

4751
after_success:
4852
- ./.travis/after-success.sh
49-
50-
notifications:
51-
email: false
52-
hipchat:
53-
rooms:
54-
secure: B46Xvke4nkoN+ivLs0Ubn64rAKOQplqDwLoE9KZDJ6O0XxiAZIZoNXcrGovP+qAB8LHRbGZvOUG4u+YZt9I41bgBAuCM2wZTFJe85IzLjROLxlSXwKDH4tey31omYTSYFKm7Tg9Gi2a6hyGN/YDytiUlmJqUvElcN0EUfkXzxS4=

.travis/before-script.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ elif [ "${PHP_CPD}" = '1' ]; then
1717
exit 0;
1818
elif [ "${PHP_MD}" = '1' ]; then
1919
exit 0;
20+
elif [ "${PHP_STAN}" = '1' ]; then
21+
exit 0;
22+
elif [ "${PHP_PHAN}" = '1' ]; then
23+
pecl install ast;
24+
exit 0;
2025
fi
2126

2227
composer require "cakephp/cakephp:${CAKE_VERSION}" --dev --no-ansi --no-progress --no-interaction;

.travis/script.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ elif [ "${PHP_MD}" = '1' ]; then
3030
excludePathsJoined=${excludePathsJoined:1};
3131

3232
vendor/bin/phpmd . text phpmd.xml --suffixes php --exclude "${excludePathsJoined}";
33+
elif [ "${PHP_STAN}" = '1' ]; then
34+
vendor/bin/phpstan analyse -c phpstan.neon -l 7 src/;
35+
elif [ "${PHP_PHAN}" = '1' ]; then
36+
vendor/bin/phan;
3337
elif [ "${PHP_COVERAGE}" = '1' ]; then
3438
vendor/bin/phpunit --coverage-clover=clover.xml;
3539
else

composer.json

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,38 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.0.0",
17+
"php": ">=7.1",
18+
"cakephp/cakephp": "^3.8",
19+
"ext-soap": "*",
1820
"composer/installers": "~1.0"
1921
},
2022
"require-dev": {
2123
"oefenweb/cakephp-codesniffer": "^3.0.0",
22-
"phpunit/phpunit": "^5.7|^6.0",
2324
"phpmd/phpmd": "^2.6",
24-
"sebastian/phpcpd": "^3.0"
25-
},
26-
"support": {
27-
"source": "https://github.com/Oefenweb/cakephp-vat-number-check",
28-
"issues": "https://github.com/Oefenweb/cakephp-vat-number-check/issues"
25+
"phpstan/phpstan": "^0.12",
26+
"phpunit/phpunit": "^5.7.14|^6.0",
27+
"psy/psysh": "@stable",
28+
"sebastian/phpcpd": "^3.0",
29+
"phan/phan": "^1.3"
2930
},
3031
"autoload": {
3132
"psr-4": {
32-
"VatNumberCheck\\": "src"
33+
"VatNumberCheck\\": "src",
34+
"VatNumberCheck\\Test\\Fixture\\": "tests/Fixture/"
3335
}
3436
},
3537
"autoload-dev": {
3638
"psr-4": {
39+
"VatNumberCheck\\Test\\TestApp\\": "tests/test_app/TestApp",
3740
"VatNumberCheck\\Test\\": "tests",
38-
"VatNumberCheck\\Test\\TestApp\\": "tests/test_app/src",
3941
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
4042
}
43+
},
44+
"support": {
45+
"issues": "https://github.com/Oefenweb/cakephp-vat-number-check/issues",
46+
"source": "https://github.com/Oefenweb/cakephp-vat-number-check"
47+
},
48+
"extra": {
49+
"installer-name": "VatNumberCheck"
4150
}
4251
}

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
autoload_files:
3+
- tests/bootstrap.php
4+
ignoreErrors:
5+
- message: '#Cannot cast array\|string\|null to string.#'
6+
path: src/Controller/VatNumberChecksController.php

src/Controller/AppController.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Controller/VatNumberChecksController.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<?php
22
namespace VatNumberCheck\Controller;
33

4+
use Cake\Controller\Controller as BaseController;
45
use Cake\Event\Event;
5-
use Cake\Network\Exception\InternalErrorException;
6+
use Cake\Http\Exception\InternalErrorException;
67
use VatNumberCheck\Utility\Model\VatNumberCheck;
78

89
/**
910
* VatNumberChecks Controller.
1011
*
1112
* @property \Cake\Controller\Component\RequestHandlerComponent $RequestHandler
12-
* @property \TextRenderers\Utility\Model\VatNumberCheck $VatNumberCheck
13+
* @property \VatNumberCheck\Utility\Model\VatNumberCheck $VatNumberCheck
1314
*/
14-
class VatNumberChecksController extends AppController
15+
class VatNumberChecksController extends BaseController
1516
{
1617
/**
1718
* An array of names of components to load.
1819
*
19-
* @var array
20+
* @var array<int,string>
2021
*/
2122
public $components = ['RequestHandler'];
2223

@@ -36,14 +37,13 @@ public function initialize()
3637
* Before action logic.
3738
*
3839
* @param \Cake\Event\Event $event The beforeRender event.
39-
* @return \Cake\Network\Response|null|void
40-
* @throws \Cake\Network\Exception\BadRequestException
40+
* @return \Cake\Http\Response|void
4141
*/
4242
public function beforeFilter(Event $event)
4343
{
4444
parent::beforeFilter($event);
4545

46-
if (in_array($this->request->action, ['check'], true)) {
46+
if (in_array($this->request->getParam('action'), ['check'], true)) {
4747
// Disable Security, Csrf component checks
4848
if ($this->components()->has('Security')) {
4949
$this->components()->unload('Security');
@@ -53,7 +53,7 @@ public function beforeFilter(Event $event)
5353
}
5454
// Allow action without authentication
5555
if ($this->components()->has('Auth')) {
56-
$this->Auth->allow($this->request->action);
56+
$this->Auth->allow($this->request->getParam('action'));
5757
}
5858
}
5959
}
@@ -65,7 +65,7 @@ public function beforeFilter(Event $event)
6565
*/
6666
public function check()
6767
{
68-
$vatNumber = (string)$this->request->data('vatNumber');
68+
$vatNumber = (string)$this->request->getData('vatNumber');
6969
$normalizeVatNumber = $this->VatNumberCheck->normalize($vatNumber);
7070

7171
$jsonData = array_merge(compact('vatNumber'), ['status' => 'failure']);
@@ -75,7 +75,7 @@ public function check()
7575
$jsonData = array_merge(compact('vatNumber'), ['status' => 'ok']);
7676
}
7777
} catch (InternalErrorException $e) {
78-
$this->response->statusCode(503);
78+
$this->response = $this->response->withStatus(503);
7979
}
8080

8181
$this->set(compact('jsonData'));

src/Plugin.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
namespace VatNumberCheck;
3+
4+
use Cake\Core\BasePlugin;
5+
6+
/**
7+
* Plugin for VatNumberCheck
8+
*/
9+
class Plugin extends BasePlugin
10+
{
11+
}

src/Utility/Model/App.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Utility/Model/VatNumberCheck.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33

44
use Cake\Core\Configure;
55
use Cake\Http\Client;
6-
use Cake\Network\Exception\InternalErrorException;
7-
use VatNumberCheck\Utility\Model\App;
6+
use Cake\Http\Exception\InternalErrorException;
87

98
/**
109
* VatNumberCheck Model.
1110
*
1211
*/
13-
class VatNumberCheck extends App
12+
class VatNumberCheck
1413
{
1514
/**
1615
* Url to check vat numbers.
1716
*
1817
*/
19-
const CHECK_URL = 'http://ec.europa.eu/taxation_customs/vies/vatResponse.html';
18+
const CHECK_URL = 'https://ec.europa.eu/taxation_customs/vies/vatResponse.html';
2019

2120
/**
2221
* Normalizes a VAT number.
@@ -33,7 +32,7 @@ public function normalize(string $vatNumber): string
3332
* Splits a VAT number into query string (data) parameters.
3433
*
3534
* @param string $vatNumber A VAT number
36-
* @return array Query string parameters
35+
* @return array<string,string> Query string parameters
3736
*/
3837
public function toQueryString(string $vatNumber): array
3938
{
@@ -61,8 +60,8 @@ public function toQueryString(string $vatNumber): array
6160
* Downloads a given url.
6261
*
6362
* @param string $url An url
64-
* @param string $data POST data
65-
* @return bool|string Request body on success (string) otherwise false (boolean)
63+
* @param array<string,string> $data POST data
64+
* @return false|string Request body on success (string) otherwise false
6665
*/
6766
public function getUrlContent(string $url, array $data)
6867
{
@@ -73,9 +72,9 @@ public function getUrlContent(string $url, array $data)
7372
$response = $HttpSocket->post($url, $data);
7473

7574
if ($response->isOk()) {
76-
return $response->body;
75+
return $response->getStringBody();
7776
}
78-
} catch (Exception $e) {
77+
} catch (\Exception $e) {
7978
}
8079

8180
return false;
@@ -86,7 +85,7 @@ public function getUrlContent(string $url, array $data)
8685
*
8786
* @param string $vatNumber A VAT number
8887
* @return bool Valid or not
89-
* @throws \Cake\Network\Exception\InternalErrorException
88+
* @throws \Cake\Http\Exception\InternalErrorException
9089
*/
9190
public function check(string $vatNumber): bool
9291
{
@@ -95,7 +94,7 @@ public function check(string $vatNumber): bool
9594

9695
$urlContent = $this->getUrlContent($url, $data);
9796
if ($urlContent) {
98-
return (strpos($urlContent, 'Yes, valid VAT number') !== false);
97+
return strpos($urlContent, 'Yes, valid VAT number') !== false;
9998
}
10099

101100
throw new InternalErrorException(__d('vat_number_check', 'Service unavailable'));

src/View/Helper/VatNumberCheckHelper.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
/**
77
* VatNumberCheck Helper.
88
*
9-
* @property Cake\View\Helper\FormHelper $Form
10-
* @property Cake\View\Helper\HtmlHelper $Html
11-
* @property Cake\View\Helper\UrlHelper $Url
9+
* @property \Cake\View\Helper\FormHelper $Form
10+
* @property \Cake\View\Helper\HtmlHelper $Html
11+
* @property \Cake\View\Helper\UrlHelper $Url
1212
*/
1313
class VatNumberCheckHelper extends Helper
1414
{
1515

1616
/**
1717
* An array of names of helpers to load.
1818
*
19-
* @var array
19+
* @var array<int,string>
2020
*/
2121
public $helpers = ['Html', 'Form', 'Url'];
2222

@@ -40,7 +40,7 @@ class VatNumberCheckHelper extends Helper
4040
* See `FormHelper::input`.
4141
*
4242
* @param string $fieldName This should be `Modelname.fieldname`
43-
* @param array $options Each type of input takes different options
43+
* @param array<string,mixed> $options Each type of input takes different options
4444
* @return string Html output for a form field
4545
*/
4646
public function input(string $fieldName, array $options = []): string
@@ -59,7 +59,7 @@ public function input(string $fieldName, array $options = []): string
5959
$options['class'] = sprintf('%s %s', $options['class'], $class);
6060
}
6161

62-
return $this->Form->input($fieldName, $options);
62+
return $this->Form->control($fieldName, $options);
6363
}
6464

6565
/**
@@ -70,7 +70,10 @@ public function input(string $fieldName, array $options = []): string
7070
protected function _addJs()
7171
{
7272
$checkUrl = $this->Url->build([
73-
'plugin' => 'VatNumberCheck', 'controller' => 'VatNumberChecks', 'action' => 'check', '_ext' => 'json'
73+
'plugin' => 'VatNumberCheck',
74+
'controller' => 'VatNumberChecks',
75+
'action' => 'check',
76+
'_ext' => 'json',
7477
]);
7578
$checkImages = [
7679
'ok' => $this->Url->build('/vat_number_check/img/ok.png'),
@@ -95,7 +98,9 @@ protected function _addJs()
9598
";
9699

97100
$this->Html->script([
98-
'VatNumberCheck.jquery.min', 'VatNumberCheck.klass.min', 'VatNumberCheck.vat_number_check'
101+
'VatNumberCheck.jquery.min',
102+
'VatNumberCheck.klass.min',
103+
'VatNumberCheck.vat_number_check',
99104
], ['inline' => false, 'once' => true]);
100105
$this->Html->scriptBlock($script, ['inline' => false]);
101106
}

0 commit comments

Comments
 (0)