Skip to content

Commit

Permalink
Add more grumphp tests and improve the inline code documentation and …
Browse files Browse the repository at this point in the history
…type hinting.
  • Loading branch information
drupol committed Oct 26, 2018
1 parent a5de9d0 commit 0df624a
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 156 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Expand Up @@ -51,3 +51,18 @@ apikey
test.php
/.php_cs.cache
/.env
grumphp.yml
node_modules
.idea/
/build/
/phpunit.xml
/runner.yml
/infection.log
/infection-log.txt
/per-mutator.md
/summary.log
/test_builder.php
/debug.log
/phpspec.yml
/phpbench.json
infection.json
32 changes: 0 additions & 32 deletions .php_cs.dist

This file was deleted.

44 changes: 1 addition & 43 deletions .scrutinizer.yml
Expand Up @@ -2,56 +2,14 @@ build: false

filter:
paths:
- 'src/*'
- 'src/*'

tools:
external_code_coverage:
timeout: 600
php_mess_detector:
config:
code_size_rules: { cyclomatic_complexity: true, npath_complexity: true, excessive_method_length: true, excessive_class_length: true, excessive_parameter_list: true, excessive_public_count: true, too_many_fields: true, too_many_methods: true, excessive_class_complexity: true }
design_rules: { number_of_class_children: true, depth_of_inheritance: true, coupling_between_objects: true }
unused_code_rules: { unused_local_variable: true, unused_private_method: true, unused_formal_parameter: true }
naming_rules: { short_variable: true, long_variable: true, short_method: true, boolean_method_name: true }
controversial_rules: { camel_case_class_name: true, camel_case_property_name: true, camel_case_method_name: true, camel_case_parameter_name: true, camel_case_variable_name: true }
php_cs_fixer:
config:
level: all
fixers: { unused_use: true, phpdoc_params: true, braces: true, php_closing_tag: true }
php_analyzer:
config:
suspicious_code: { enabled: true, overriding_parameter: true, overriding_closure_use: true, parameter_closure_use_conflict: true, parameter_multiple_times: true, non_existent_class_in_instanceof_check: true, non_existent_class_in_catch_clause: true, assignment_of_null_return: true, non_commented_switch_fallthrough: true, non_commented_empty_catch_block: true, overriding_private_members: true, use_statement_alias_conflict: true, precedence_in_condition_assignment: true }
verify_php_doc_comments: { enabled: true, parameters: true, return: true, suggest_more_specific_types: true, ask_for_return_if_not_inferrable: true, ask_for_param_type_annotation: true }
loops_must_use_braces: { enabled: true }
simplify_boolean_return: { enabled: true }
phpunit_checks: { enabled: true }
reflection_fixes: { enabled: true }
use_statement_fixes: { enabled: true, order_alphabetically: true, remove_unused: true, preserve_multiple: false, preserve_blanklines: false }
parameter_reference_check: { enabled: false }
checkstyle: { enabled: false, no_trailing_whitespace: true, naming: { enabled: true, local_variable: '^[a-z][a-zA-Z0-9]*$', abstract_class_name: ^Abstract|Factory$, utility_class_name: 'Utils?$', constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$', property_name: '^[a-z][a-zA-Z0-9]*$', method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$', parameter_name: '^[a-z][a-zA-Z0-9]*$', interface_name: '^[A-Z][a-zA-Z0-9]*Interface$', type_name: '^[A-Z][a-zA-Z0-9]*$', exception_name: '^[A-Z][a-zA-Z0-9]*Exception$', isser_method_name: '^(?:is|has|should|may|supports)' } }
unreachable_code: { enabled: false }
check_access_control: { enabled: false }
typo_checks: { enabled: false }
check_variables: { enabled: false }
check_calls: { enabled: true, too_many_arguments: true, missing_argument: true, argument_type_checks: lenient }
dead_assignments: { enabled: false }
check_usage_context: { enabled: true, foreach: { value_as_reference: true, traversable: true } }
reflection_checks: { enabled: false }
precedence_checks: { enabled: true, assignment_in_condition: true, comparison_of_bit_result: true }
basic_semantic_checks: { enabled: false }
unused_code: { enabled: false }
deprecation_checks: { enabled: false }
useless_function_calls: { enabled: false }
metrics_lack_of_cohesion_methods: { enabled: false }
metrics_coupling: { enabled: true, stable_code: { namespace_prefixes: { }, classes: { } } }
doctrine_parameter_binding: { enabled: false }
doctrine_entity_manager_injection: { enabled: false }
symfony_request_injection: { enabled: false }
doc_comment_fixes: { enabled: false }
php_code_sniffer:
config:
standard: PSR2
sniffs: { psr2: { classes: { property_declaration_sniff: true }, methods: { method_declaration_sniff: true } } }
sensiolabs_security_checker: true
php_loc: true
php_pdepend: true
Expand Down
5 changes: 5 additions & 0 deletions apigen.yml
@@ -0,0 +1,5 @@
parameters:
visibility_levels: [public, protected, private]
title: "drupol/yaroc API documentation"
base_url: "https://not-a-number.io/yaroc"
overwrite: false
44 changes: 28 additions & 16 deletions composer.json
Expand Up @@ -4,7 +4,7 @@
"description": "YAROC: Yet Another Random.Org Client.",
"keywords": ["random", "client", "random.org", "RNG"],
"type": "library",
"license": "GPL-2.0+",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"support": {
Expand All @@ -20,39 +20,51 @@
],
"require": {
"php": ">=7",
"ext-json": "*",
"php-http/httplug": "^1.1",
"php-http/discovery": "^1.4",
"php-http/client-common": "^1.7",
"symfony/dotenv": "^4.0"
},
"require-dev": {
"php-http/guzzle6-adapter": "^1.1",
"squizlabs/php_codesniffer": "^3",
"codacy/coverage": "dev-master",
"scrutinizer/ocular": "^1.3",
"monolog/monolog": "^1.0",
"friendsofphp/php-cs-fixer": "*",
"sensiolabs/security-checker": "^4.1",
"phpspec/phpspec": "^4.3",
"scrutinizer/ocular": "^1.5",
"codacy/coverage": "^1.4",
"drupol/phpspec-annotation": "^1.0",
"phpro/grumphp": "^0.14.0",
"leanphp/phpspec-code-coverage": "^4.2",
"friendsofphp/php-cs-fixer": "^2.10",
"jakub-onderka/php-parallel-lint": "^1.0",
"sebastian/phpcpd": "^4.0"
"leanphp/phpspec-code-coverage": "^4",
"maglnet/composer-require-checker": "^1.1",
"monolog/monolog": "^1.0",
"php-http/guzzle6-adapter": "^1.1",
"phpmd/phpmd": "^2.6",
"phpro/grumphp": "^0.14.0",
"phpspec/phpspec": "^4",
"phpstan/phpstan": "^0.10.3",
"roave/security-advisories": "dev-master",
"sebastian/phpcpd": "^4.0",
"sensiolabs/security-checker": "^4.1",
"squizlabs/php_codesniffer": "^3",
"infection/infection": "^0.10.5",
"apigen/apigen": "dev-master",
"roave/better-reflection": "dev-master",
"ircmaxell/random-lib": "^1.2",
"rych/random": "^0.1.0"
},
"scripts": {
"apigen": "./vendor/bin/apigen generate src --destination build/docs",
"phpspec": "./vendor/bin/phpspec run",
"grumphp": "./vendor/bin/grumphp run",
"phpcs": "./vendor/bin/phpcs --ignore=vendor .",
"phpcbf": "./vendor/bin/phpcbf --ignore=vendor .",
"codacy": "./vendor/bin/codacycoverage clover build/logs/clover.xml",
"coveralls": "./vendor/bin/php-coveralls",
"scrutinizer": "./vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml"
"infection": "./vendor/bin/infection run -j 10",
"scrutinizer": "./vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml",
"bench": "./vendor/bin/phpbench run --report=project --store --precision=3"
},
"autoload": {
"psr-4": {
"drupol\\Yaroc\\": "src/",
"drupol\\Yaroc\\Tests\\": "tests/src/"
"drupol\\Yaroc\\Tests\\": "tests/src/",
"drupol\\Yaroc\\Examples\\": "examples/"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 24 additions & 15 deletions grumphp.yml.dist
Expand Up @@ -3,12 +3,16 @@ parameters:
bin_dir: vendor/bin
tasks:
phplint: ~
yamllint: ~
composer: ~
phpcpd: ~
phpcpd:
directory: './src'
jsonlint: ~
phpstan:
autoload_file: ~
configuration: ~
level: 7
force_patterns: []
ignore_patterns: ['/spec/', '/benchmarks/', '/examples/']
triggered_by: ['php']
phpcsfixer:
config_file: ~
config: ~
Expand All @@ -22,17 +26,22 @@ parameters:
- spec/
triggered_by:
- php
- module
- inc
- js
phpspec:
format: pretty
stop_on_failure: true
verbose: true
format: pretty
stop_on_failure: true
verbose: true
securitychecker:
lockfile: ./composer.lock
format: ~
end_point: ~
timeout: ~
run_always: false

lockfile: ./composer.lock
format: ~
end_point: ~
timeout: ~
run_always: false
composer_require_checker:
composer_file: 'composer.json'
config_file: ~
ignore_parse_errors: false
triggered_by: ['composer.json', 'composer.lock', '*.php']
infection:
threads: 10
min_msi: 30
min_covered_msi: 30
19 changes: 19 additions & 0 deletions infection.json.dist
@@ -0,0 +1,19 @@
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "infection.log",
"summary": "summary.log",
"debug": "debug.log",
"perMutator": "per-mutator.md",
"badge": {
"branch": "master"
}
},
"testFramework":"phpspec",
"tmpDir": "build"
}
8 changes: 3 additions & 5 deletions phpspec.yml.dist
@@ -1,15 +1,13 @@
formatter.name: pretty

extensions:
drupol\PhpspecAnnotation\PhpspecAnnotation: ~
LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension:
blacklist:
- src/test
format:
- html
- clover
- php
- text
output:
html: build/coverage
clover: build/logs/clover.xml
php: build/coverage.php
clover: build/coverage.xml
php: build/coverage.php
2 changes: 1 addition & 1 deletion spec/drupol/Yaroc/RandomOrgAPISpec.php
Expand Up @@ -92,7 +92,7 @@ public function it_can_return_the_right_errorcode()
->withParameters(['n' => 10, 'min' => 0, 'max' => 100, 'unexistent' => 'test']);
$this->shouldThrow(\InvalidArgumentException::class)->during('call', [$provider]);

$provider = Provider::withResource('unexistentResourse')
$provider = Provider::withResource('unexistentResource')
->withParameters([]);
$this->shouldThrow(\BadFunctionCallException::class)->during('call', [$provider]);

Expand Down
2 changes: 1 addition & 1 deletion src/Http/AbstractClient.php
Expand Up @@ -24,7 +24,7 @@ abstract class AbstractClient
/**
* The HTTP message factory.
*
* @var \Http\Message\MessageFactory|null
* @var \Http\Message\MessageFactory
*/
private $messageFactory;

Expand Down
18 changes: 8 additions & 10 deletions src/Plugin/AbstractProvider.php
Expand Up @@ -36,22 +36,20 @@ abstract class AbstractProvider extends AbstractClient implements ProviderInterf
*/
public function request() :ResponseInterface
{
$parameters = [
'jsonrpc' => '2.0',
'id' => uniqid($this->getResource() . '_', true),
'params' => $this->getParameters(),
'method' => $this->getResource(),
];
$body = (string) \json_encode([
'jsonrpc' => '2.0',
'id' => \uniqid($this->getResource() . '_', true),
'params' => $this->getParameters(),
'method' => $this->getResource(),
]);

try {
$response = $this->getHttpClient()->sendRequest(
$this->getMessageFactory()->createRequest(
'POST',
$this->getEndpoint(),
$this->getEndPoint(),
[],
json_encode(
$parameters
)
$body
)
);
} catch (HttpException $exception) {
Expand Down
12 changes: 6 additions & 6 deletions src/Plugin/ProviderInterface.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace drupol\Yaroc\Plugin;

use Http\Client\HttpClient;
Expand All @@ -10,28 +12,28 @@ interface ProviderInterface
/**
* @param string $endpoint
*
* @return $this
* @return ProviderInterface
*/
public function withEndPoint(string $endpoint) :ProviderInterface;

/**
* @param array $parameters
*
* @return $this
* @return ProviderInterface
*/
public function withParameters(array $parameters) :ProviderInterface;

/**
* @param \Http\Client\HttpClient $httpClient
*
* @return $this
* @return ProviderInterface
*/
public function withHttpClient(HttpClient $httpClient);

/**
* @param string $resource
*
* @return \drupol\Yaroc\Plugin\ProviderInterface
* @return ProviderInterface
*/
public static function withResource(string $resource) :ProviderInterface;

Expand Down Expand Up @@ -59,8 +61,6 @@ public function getParameters() :array;
/**
* Do the request.
*
* @throws \Exception|\Http\Client\Exception
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function request() :ResponseInterface;
Expand Down

0 comments on commit 0df624a

Please sign in to comment.