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

Commit

Permalink
Upgrade to Domrobot v3 and adjust pipeline, Fix codestyle (#11)
Browse files Browse the repository at this point in the history
* Upgrade Domrobot-Client from INWX to v3
* Bump versions to latest supported PHP and Symfony-Versions
* Fix deprecations
* Improve tests
* Switch to Github Actions
  • Loading branch information
SebTM authored Dec 22, 2019
1 parent 67746ae commit eb8c282
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 218 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
coverage_clover: build/logs/clover.xml
service_name: travis-pro
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: INWX-API-Bundle
on: ["push", "pull_request"]
jobs:
run:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
symfony-versions: ['3.4.*', '4.2.*', '4.3.*', '4.4.*', '5.0.*']
name: PHP ${{ matrix.php-versions }} with Symfony ${{ matrix.symfony-versions }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
coverage: xdebug
extensions: mbstring
ini-values: memory_limit=1G
php-version: ${{ matrix.php-versions }}
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install Symfony
run: composer require --dev --no-update symfony/framework-bundle:${{ matrix.symfony-versions }}
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: iab-php${{ matrix.php-versions }}-sf${{ matrix.symfony-versions }}
restore-keys: iab-php${{ matrix.php-versions }}-sf${{ matrix.symfony-versions }}
- name: Run linter
run: ./vendor/bin/php-cs-fixer fix --diff --dry-run --no-interaction -v
- name: Run tests
run: ./vendor/bin/phpunit -c phpunit.dist.xml
env:
INWX_API_USERNAME: ${{ secrets.INWX_API_USERNAME }}
INWX_API_PASSWORD: ${{ secrets.INWX_API_PASSWORD }}
- name: Send to coveralls
run: ./vendor/bin/php-coveralls -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
46 changes: 0 additions & 46 deletions .travis.yml

This file was deleted.

18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ requiring the `sebtm/inwx-api-bundle` package in your project's `composer.json`:
```json
{
"require": {
"sebtm/inwx-api-bundle": "~0.3"
"sebtm/inwx-api-bundle": "~1.0"
}
}
```
Expand All @@ -25,14 +25,12 @@ and adding an instance of `SebTM\INWX\InwxApiBundle` to your application's kerne
```php
class AppKernel extends Kernel
{
public function registerBundles()
public function registerBundles(): void
{
return [
...
new \SebTM\INWX\InwxApiBundle(),
];
}
...
}
```
(This is NOT needed for Symfony-Flex while using recipes!)
Expand All @@ -44,14 +42,15 @@ The sample configuration which can be placed in `app/config/config.yml` file.

```yaml
inwx_api:
environment: "production"
debug: false
environment: "development"
json: true
language: "en"
username: "username"
password: "password"
language: "en"
debug: false
```
Supported environments: "production", "test"
Supported environments: "production", "development"
Supported languages: see documentation of INWX PHP-Client
## Usage
Expand All @@ -64,6 +63,9 @@ Service | Instance Of
inwx_api | SebTM\INWX\Domrobot
```
It provides an additional function called "loginWrapper()" (BC >=1.0.0: login will not overwritten anymore!) for using
the login data from configuration.
## Links
* [INWX PHP-Client on Github](https://github.com/inwx/php-client)
* [INWX PHP-Client Documentation](https://www.inwx.de/en/help/apidoc)
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
}
],
"require": {
"php": ">=7.1",
"inwx/domrobot": "^2.4",
"symfony/config": "^3.4|^4.1|^4.2",
"symfony/http-kernel": "^3.4|^4.1|^4.2",
"symfony/yaml": "^3.4|^4.1|^4.2"
"php": ">=7.2",
"inwx/domrobot": "^3.0",
"symfony/config": "^3.4|^4.2|^4.3|^4.4|^5.0",
"symfony/http-kernel": "^3.4|^4.2|^4.3|^4.4|^5.0",
"symfony/yaml": "^3.4|^4.2|^4.3|^4.4|^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2",
Expand Down
28 changes: 14 additions & 14 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@

class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('inwx_api');
$treeBuilder = new TreeBuilder('inwx_api');

$rootNode
$treeBuilder
->getRootNode()
->children()
->booleanNode('debug')
->defaultFalse()
->end()
->enumNode('environment')
->values(
array(
'production',
'test',
'development',
)
)
->defaultValue('test')
->defaultValue('development')
->end()
->booleanNode('json')
->defaultTrue()
->end()
->scalarNode('language')
->defaultValue('en')
->end()
->scalarNode('username')
->isRequired()
->end()
->scalarNode('password')
->isRequired()
->end()
->scalarNode('language')
->defaultValue('en')
->end()
->booleanNode('debug')
->defaultFalse()
->end()
->end();

return $treeBuilder;
Expand Down
17 changes: 8 additions & 9 deletions src/DependencyInjection/InwxApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
class InwxApiExtension extends Extension
{
/**
* @param array $configs
* @param ContainerBuilder $container
*
* @throws \Exception Error occurred while parsing "services.yml"
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand All @@ -25,11 +22,13 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
$loader->load('services.yml');

$options = \array_filter($config, static function (string $key) {
return 'username' !== $key && 'password' !== $key;
}, ARRAY_FILTER_USE_KEY);

$definition = $container->getDefinition('inwx_api');
$definition->replaceArgument(0, $config['environment']);
$definition->replaceArgument(1, $config['username']);
$definition->replaceArgument(2, $config['password']);
$definition->replaceArgument(3, $config['language']);
$definition->replaceArgument(4, $config['debug']);
$definition->replaceArgument(0, $config['username']);
$definition->replaceArgument(1, $config['password']);
$definition->replaceArgument(2, $options);
}
}
73 changes: 16 additions & 57 deletions src/Domrobot.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@

use INWX\Domrobot as BaseDomrobot;
use SebTM\INWX\Exception\LoginUnsuccessfulException;
use SebTM\INWX\Exception\UnsupportedEnvironmentException;

class Domrobot extends BaseDomrobot
{
/**
* @var string
*/
protected $environment;

/**
* @var string
*/
Expand All @@ -23,71 +17,36 @@ class Domrobot extends BaseDomrobot
*/
protected $password;

/**
* @param string $environment
* @param string $username
* @param string $password
* @param string $language
* @param bool $debug
*
* @throws UnsupportedEnvironmentException
*/
public function __construct($environment, $username, $password, $language = 'en', $debug = false)
public function __construct(string $username, string $password, array $options = array())
{
$this->environment = $environment;
parent::__construct();

$this->username = $username;
$this->password = $password;

parent::__construct($this->getApiUrl());

$this->setLanguage($language);
$this->setDebug($debug);
}

/**
* @throws UnsupportedEnvironmentException
*
* @return string
*/
public function getApiUrl(): string
{
switch ($this->environment) {
case 'production':
return 'https://api.domrobot.com/xmlrpc/';
if (\array_key_exists('debug', $options) && true === $options['debug']) {
$this->setDebug(true);
}

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

default:
throw new UnsupportedEnvironmentException();
if (\array_key_exists('json', $options) && false === $options['json']) {
$this->useXml();
}
}

/**
* @return string
*/
public function getEnvironment(): string
{
return $this->environment;
if (\array_key_exists('language', $options)) {
$this->setLanguage($options['language']);
}
}

/**
* @param null|string $username Should not be set to use values from DI - must have method signature compatible
* @param null|string $password Should not be set to use values from DI - must have method signature compatible
* @param null|string $sharedSecret
*
* @throws LoginUnsuccessfulException
*
* @return bool
*/
public function login($username = null, $password = null, $sharedSecret = null): bool
public function loginWrapper(): bool
{
if (null === $username && null === $password) {
$username = $this->username;
$password = $this->password;
}

$result = parent::login($username, $password, $sharedSecret);
$result = $this->login($this->username, $this->password);

if (1000 === $result['code']) {
return true;
Expand Down
11 changes: 0 additions & 11 deletions src/Exception/UnsupportedEnvironmentException.php

This file was deleted.

8 changes: 5 additions & 3 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
services:
inwx_api:
arguments:
- '%inwx_api.environment%'
- '%inwx_api.username%'
- '%inwx_api.password%'
- '%inwx_api.language%'
- '%inwx_api.debug%'
- options:
- debug: '%inwx_api.debug%'
- environment: '%inwx_api.environment%'
- json: '%inwx_api.json%'
- language: '%inwx_api.language%'
class: SebTM\INWX\Domrobot
public: true
Loading

0 comments on commit eb8c282

Please sign in to comment.