Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

Commit eb8c282

Browse files
authored
Upgrade to Domrobot v3 and adjust pipeline, Fix codestyle (#11)
* Upgrade Domrobot-Client from INWX to v3 * Bump versions to latest supported PHP and Symfony-Versions * Fix deprecations * Improve tests * Switch to Github Actions
1 parent 67746ae commit eb8c282

14 files changed

+245
-218
lines changed

.coveralls.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
coverage_clover: build/logs/clover.xml
2-
service_name: travis-pro

.github/workflows/main.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: INWX-API-Bundle
2+
on: ["push", "pull_request"]
3+
jobs:
4+
run:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
php-versions: ['7.2', '7.3', '7.4']
9+
symfony-versions: ['3.4.*', '4.2.*', '4.3.*', '4.4.*', '5.0.*']
10+
name: PHP ${{ matrix.php-versions }} with Symfony ${{ matrix.symfony-versions }}
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
- name: Setup PHP
15+
uses: shivammathur/setup-php@v1
16+
with:
17+
coverage: xdebug
18+
extensions: mbstring
19+
ini-values: memory_limit=1G
20+
php-version: ${{ matrix.php-versions }}
21+
- name: Get Composer Cache Directory
22+
id: composer-cache
23+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
24+
- name: Validate composer.json and composer.lock
25+
run: composer validate
26+
- name: Install Symfony
27+
run: composer require --dev --no-update symfony/framework-bundle:${{ matrix.symfony-versions }}
28+
- name: Install dependencies
29+
run: composer install --prefer-dist --no-progress --no-suggest
30+
- uses: actions/cache@v1
31+
with:
32+
path: ${{ steps.composer-cache.outputs.dir }}
33+
key: iab-php${{ matrix.php-versions }}-sf${{ matrix.symfony-versions }}
34+
restore-keys: iab-php${{ matrix.php-versions }}-sf${{ matrix.symfony-versions }}
35+
- name: Run linter
36+
run: ./vendor/bin/php-cs-fixer fix --diff --dry-run --no-interaction -v
37+
- name: Run tests
38+
run: ./vendor/bin/phpunit -c phpunit.dist.xml
39+
env:
40+
INWX_API_USERNAME: ${{ secrets.INWX_API_USERNAME }}
41+
INWX_API_PASSWORD: ${{ secrets.INWX_API_PASSWORD }}
42+
- name: Send to coveralls
43+
run: ./vendor/bin/php-coveralls -v
44+
env:
45+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

.travis.yml

-46
This file was deleted.

README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ requiring the `sebtm/inwx-api-bundle` package in your project's `composer.json`:
1515
```json
1616
{
1717
"require": {
18-
"sebtm/inwx-api-bundle": "~0.3"
18+
"sebtm/inwx-api-bundle": "~1.0"
1919
}
2020
}
2121
```
@@ -25,14 +25,12 @@ and adding an instance of `SebTM\INWX\InwxApiBundle` to your application's kerne
2525
```php
2626
class AppKernel extends Kernel
2727
{
28-
public function registerBundles()
28+
public function registerBundles(): void
2929
{
3030
return [
31-
...
3231
new \SebTM\INWX\InwxApiBundle(),
3332
];
3433
}
35-
...
3634
}
3735
```
3836
(This is NOT needed for Symfony-Flex while using recipes!)
@@ -44,14 +42,15 @@ The sample configuration which can be placed in `app/config/config.yml` file.
4442

4543
```yaml
4644
inwx_api:
47-
environment: "production"
45+
debug: false
46+
environment: "development"
47+
json: true
48+
language: "en"
4849
username: "username"
4950
password: "password"
50-
language: "en"
51-
debug: false
5251
```
5352
54-
Supported environments: "production", "test"
53+
Supported environments: "production", "development"
5554
Supported languages: see documentation of INWX PHP-Client
5655
5756
## Usage
@@ -64,6 +63,9 @@ Service | Instance Of
6463
inwx_api | SebTM\INWX\Domrobot
6564
```
6665
66+
It provides an additional function called "loginWrapper()" (BC >=1.0.0: login will not overwritten anymore!) for using
67+
the login data from configuration.
68+
6769
## Links
6870
* [INWX PHP-Client on Github](https://github.com/inwx/php-client)
6971
* [INWX PHP-Client Documentation](https://www.inwx.de/en/help/apidoc)

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=7.1",
16-
"inwx/domrobot": "^2.4",
17-
"symfony/config": "^3.4|^4.1|^4.2",
18-
"symfony/http-kernel": "^3.4|^4.1|^4.2",
19-
"symfony/yaml": "^3.4|^4.1|^4.2"
15+
"php": ">=7.2",
16+
"inwx/domrobot": "^3.0",
17+
"symfony/config": "^3.4|^4.2|^4.3|^4.4|^5.0",
18+
"symfony/http-kernel": "^3.4|^4.2|^4.3|^4.4|^5.0",
19+
"symfony/yaml": "^3.4|^4.2|^4.3|^4.4|^5.0"
2020
},
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "~2",

src/DependencyInjection/Configuration.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@
77

88
class Configuration implements ConfigurationInterface
99
{
10-
/**
11-
* @return TreeBuilder
12-
*/
1310
public function getConfigTreeBuilder(): TreeBuilder
1411
{
15-
$treeBuilder = new TreeBuilder();
16-
$rootNode = $treeBuilder->root('inwx_api');
12+
$treeBuilder = new TreeBuilder('inwx_api');
1713

18-
$rootNode
14+
$treeBuilder
15+
->getRootNode()
1916
->children()
17+
->booleanNode('debug')
18+
->defaultFalse()
19+
->end()
2020
->enumNode('environment')
2121
->values(
2222
array(
2323
'production',
24-
'test',
24+
'development',
2525
)
2626
)
27-
->defaultValue('test')
27+
->defaultValue('development')
28+
->end()
29+
->booleanNode('json')
30+
->defaultTrue()
31+
->end()
32+
->scalarNode('language')
33+
->defaultValue('en')
2834
->end()
2935
->scalarNode('username')
3036
->isRequired()
3137
->end()
3238
->scalarNode('password')
3339
->isRequired()
3440
->end()
35-
->scalarNode('language')
36-
->defaultValue('en')
37-
->end()
38-
->booleanNode('debug')
39-
->defaultFalse()
40-
->end()
4141
->end();
4242

4343
return $treeBuilder;

src/DependencyInjection/InwxApiExtension.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
class InwxApiExtension extends Extension
1111
{
1212
/**
13-
* @param array $configs
14-
* @param ContainerBuilder $container
15-
*
1613
* @throws \Exception Error occurred while parsing "services.yml"
1714
*/
18-
public function load(array $configs, ContainerBuilder $container)
15+
public function load(array $configs, ContainerBuilder $container): void
1916
{
2017
$configuration = new Configuration();
2118
$config = $this->processConfiguration($configuration, $configs);
@@ -25,11 +22,13 @@ public function load(array $configs, ContainerBuilder $container)
2522
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
2623
$loader->load('services.yml');
2724

25+
$options = \array_filter($config, static function (string $key) {
26+
return 'username' !== $key && 'password' !== $key;
27+
}, ARRAY_FILTER_USE_KEY);
28+
2829
$definition = $container->getDefinition('inwx_api');
29-
$definition->replaceArgument(0, $config['environment']);
30-
$definition->replaceArgument(1, $config['username']);
31-
$definition->replaceArgument(2, $config['password']);
32-
$definition->replaceArgument(3, $config['language']);
33-
$definition->replaceArgument(4, $config['debug']);
30+
$definition->replaceArgument(0, $config['username']);
31+
$definition->replaceArgument(1, $config['password']);
32+
$definition->replaceArgument(2, $options);
3433
}
3534
}

src/Domrobot.php

+16-57
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@
44

55
use INWX\Domrobot as BaseDomrobot;
66
use SebTM\INWX\Exception\LoginUnsuccessfulException;
7-
use SebTM\INWX\Exception\UnsupportedEnvironmentException;
87

98
class Domrobot extends BaseDomrobot
109
{
11-
/**
12-
* @var string
13-
*/
14-
protected $environment;
15-
1610
/**
1711
* @var string
1812
*/
@@ -23,71 +17,36 @@ class Domrobot extends BaseDomrobot
2317
*/
2418
protected $password;
2519

26-
/**
27-
* @param string $environment
28-
* @param string $username
29-
* @param string $password
30-
* @param string $language
31-
* @param bool $debug
32-
*
33-
* @throws UnsupportedEnvironmentException
34-
*/
35-
public function __construct($environment, $username, $password, $language = 'en', $debug = false)
20+
public function __construct(string $username, string $password, array $options = array())
3621
{
37-
$this->environment = $environment;
22+
parent::__construct();
23+
3824
$this->username = $username;
3925
$this->password = $password;
4026

41-
parent::__construct($this->getApiUrl());
42-
43-
$this->setLanguage($language);
44-
$this->setDebug($debug);
45-
}
46-
47-
/**
48-
* @throws UnsupportedEnvironmentException
49-
*
50-
* @return string
51-
*/
52-
public function getApiUrl(): string
53-
{
54-
switch ($this->environment) {
55-
case 'production':
56-
return 'https://api.domrobot.com/xmlrpc/';
27+
if (\array_key_exists('debug', $options) && true === $options['debug']) {
28+
$this->setDebug(true);
29+
}
5730

58-
case 'test':
59-
return 'https://api.ote.domrobot.com/xmlrpc/';
31+
if (\array_key_exists('environment', $options) && 'production' === $options['environment']) {
32+
$this->useLive();
33+
}
6034

61-
default:
62-
throw new UnsupportedEnvironmentException();
35+
if (\array_key_exists('json', $options) && false === $options['json']) {
36+
$this->useXml();
6337
}
64-
}
6538

66-
/**
67-
* @return string
68-
*/
69-
public function getEnvironment(): string
70-
{
71-
return $this->environment;
39+
if (\array_key_exists('language', $options)) {
40+
$this->setLanguage($options['language']);
41+
}
7242
}
7343

7444
/**
75-
* @param null|string $username Should not be set to use values from DI - must have method signature compatible
76-
* @param null|string $password Should not be set to use values from DI - must have method signature compatible
77-
* @param null|string $sharedSecret
78-
*
7945
* @throws LoginUnsuccessfulException
80-
*
81-
* @return bool
8246
*/
83-
public function login($username = null, $password = null, $sharedSecret = null): bool
47+
public function loginWrapper(): bool
8448
{
85-
if (null === $username && null === $password) {
86-
$username = $this->username;
87-
$password = $this->password;
88-
}
89-
90-
$result = parent::login($username, $password, $sharedSecret);
49+
$result = $this->login($this->username, $this->password);
9150

9251
if (1000 === $result['code']) {
9352
return true;

src/Exception/UnsupportedEnvironmentException.php

-11
This file was deleted.

src/Resources/config/services.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
services:
22
inwx_api:
33
arguments:
4-
- '%inwx_api.environment%'
54
- '%inwx_api.username%'
65
- '%inwx_api.password%'
7-
- '%inwx_api.language%'
8-
- '%inwx_api.debug%'
6+
- options:
7+
- debug: '%inwx_api.debug%'
8+
- environment: '%inwx_api.environment%'
9+
- json: '%inwx_api.json%'
10+
- language: '%inwx_api.language%'
911
class: SebTM\INWX\Domrobot
1012
public: true

0 commit comments

Comments
 (0)