Skip to content

Commit

Permalink
chore: remove coke, use cs-fixer and add a makefile (#65)
Browse files Browse the repository at this point in the history
* chore: remove coke, use cs-fixer and add a makefile

* Apply suggestions from code review

Co-Authored-By: Oliver THEBAULT <[email protected]>

* chore: pr feedbacks

* chore: update travis build

* chore: fix composer.json after rebase

* chore: use PHP71 config to be compatible with CI

* chore: remove sf-security-checker in make ci

* chore: remove test-dependecies target all together

* chore: remove unused code in makefile & travis config
  • Loading branch information
GautierLB authored Dec 18, 2019
1 parent 8711bf2 commit 1da320f
Show file tree
Hide file tree
Showing 26 changed files with 182 additions and 210 deletions.
8 changes: 0 additions & 8 deletions .coke

This file was deleted.

6 changes: 6 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Why?
<!-- Explain why you've done it like this -->

## How?
<!-- Explain how you've done it -->

11 changes: 11 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$config = new M6Web\CS\Config\Php71();
$config
->getFinder()
->in(
[
__DIR__.'/src',
]
);

return $config;
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ before_install:

install:
- composer update $COMPOSER_FLAGS --prefer-dist -n
- if [ "$COMPOSER_PREFER" = "lowest" ]; then composer update --prefer-lowest -n; fi;

script:
- bin/coke
- bin/atoum
- make ci
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
SHELL=bash
SOURCE_DIR = $(shell pwd)
BIN_DIR = ${SOURCE_DIR}/bin
COMPOSER = composer

define printSection
@printf "\033[36m\n==================================================\n\033[0m"
@printf "\033[36m $1 \033[0m"
@printf "\033[36m\n==================================================\n\033[0m"
endef

.PHONY: all
all: install quality test test-dependencies

.PHONY: ci
ci: quality test

.PHONY: install
install: clean-vendor composer-install

.PHONY: quality
quality: cs-ci

.PHONY: test
test: atoum

# Coding Style

.PHONY: cs
cs:
${BIN_DIR}/php-cs-fixer fix --dry-run --stop-on-violation --diff

.PHONY: cs-fix
cs-fix:
${BIN_DIR}/php-cs-fixer fix

.PHONY: cs-ci
cs-ci:
${BIN_DIR}/php-cs-fixer fix --ansi --dry-run --using-cache=no --verbose

#COMPOSER

.PHONY: clean-vendor
clean-vendor:
$(call printSection,CLEAN-VENDOR)
rm -rf ${SOURCE_DIR}/vendor

.PHONY: composer-install
composer-install: ${SOURCE_DIR}/vendor/composer/installed.json

${SOURCE_DIR}/vendor/composer/installed.json:
$(call printSection,COMPOSER INSTALL)
$(COMPOSER) --no-interaction install --ansi --no-progress --prefer-dist

# CI TOOLS

# TEST
.PHONY: atoum
atoum:
$(call printSection,TEST atoum)
${BIN_DIR}/atoum

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ First of all, thank you for contributing !

Here are few rules to follow for a easier code review before the maintainers accept and merge your request.

- you MUST follow the Symfony2 coding standard : you can use `./bin/coke` to validate
- you MUST follow the Symfony2 coding standard : you can use `make cs-fix` to fix the files
- you MUST run the test
- you MUST write or update tests
- you MUST write or update documentation
Expand All @@ -281,11 +281,11 @@ Here are few rules to follow for a easier code review before the maintainers acc
Install the composer dev dependencies

```shell
$ composer install --dev
make install
```

Then run the test with [atoum](https://github.com/atoum/atoum) unit test framework

```shell
./bin/atoum
make test
```
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"require-dev": {
"atoum/atoum": "~3.1",
"atoum/stubs": "*",
"m6web/coke": "~2.2",
"m6web/symfony2-coding-standard": "~3.3"
"m6web/php-cs-fixer-config": "^1.0"
},
"autoload": {
"psr-4": {"M6Web\\Bundle\\GuzzleHttpBundle\\": "src/"}
Expand Down
11 changes: 6 additions & 5 deletions src/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace M6Web\Bundle\GuzzleHttpBundle\Cache;

/**
Expand All @@ -11,7 +12,7 @@ interface CacheInterface
*
* @param string $key A unique key
*
* @return Boolean Whether the cache has a value for this key
* @return bool Whether the cache has a value for this key
*/
public function has($key);

Expand All @@ -27,9 +28,9 @@ public function get($key);
/**
* Sets a value in the cache.
*
* @param string $key A unique key
* @param string $value The value to cache
* @param integer $ttl Time to live in seconds
* @param string $key A unique key
* @param string $value The value to cache
* @param int $ttl Time to live in seconds
*/
public function set($key, $value, $ttl = null);

Expand All @@ -45,7 +46,7 @@ public function remove($key);
*
* @param string $key The key
*
* @return integer|false the ttl or false
* @return int|false the ttl or false
*/
public function ttl($key);
}
15 changes: 8 additions & 7 deletions src/Cache/InMemory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace M6Web\Bundle\GuzzleHttpBundle\Cache;

/**
Expand All @@ -7,10 +8,10 @@
class InMemory implements CacheInterface
{
protected $cache = [];
protected $ttl = [];
protected $ttl = [];

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function has($key)
{
Expand All @@ -25,7 +26,7 @@ public function has($key)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function get($key)
{
Expand All @@ -37,16 +38,16 @@ public function get($key)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function set($key, $value, $ttl = null)
{
$this->cache[$key] = $value;
$this->ttl[$key] = is_null($ttl) ? null : microtime(true) + $ttl;
$this->ttl[$key] = is_null($ttl) ? null : microtime(true) + $ttl;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function remove($key)
{
Expand All @@ -57,7 +58,7 @@ public function remove($key)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function ttl($key)
{
Expand Down
14 changes: 7 additions & 7 deletions src/DataCollector/GuzzleHttpDataCollector.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace M6Web\Bundle\GuzzleHttpBundle\DataCollector;

use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use M6Web\Bundle\GuzzleHttpBundle\EventDispatcher\AbstractGuzzleHttpEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;

/**
* Collect information about guzzlehttp client
Expand All @@ -21,6 +22,7 @@ public function __construct()

/**
* Collect the data
*
* @param Request $request The request object
* @param Response $response The response object
* @param \Exception $exception An exception
Expand Down Expand Up @@ -53,8 +55,6 @@ public function getName()

/**
* Collect data for GuzzleHttp
*
* @param AbstractGuzzleHttpEvent $event
*/
public function onGuzzleHttpCommand(AbstractGuzzleHttpEvent $event)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public function getAvgExecutionTime()
{
$totalExecutionTime = $this->getTotalExecutionTime();

return ($totalExecutionTime) ? ($totalExecutionTime / count($this->getCommands()) ) : 0;
return ($totalExecutionTime) ? ($totalExecutionTime / count($this->getCommands())) : 0;
}

/**
Expand Down Expand Up @@ -194,6 +194,6 @@ public function getAvgRedirectionTime()
{
$totalExecutionTime = $this->getTotalRedirectionTime();

return ($totalExecutionTime) ? ($totalExecutionTime / count($this->getRedirects()) ) : 0;
return ($totalExecutionTime) ? ($totalExecutionTime / count($this->getRedirects())) : 0;
}
}
9 changes: 5 additions & 4 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace M6Web\Bundle\GuzzleHttpBundle\DependencyInjection;

use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
Expand All @@ -13,7 +14,7 @@ class Configuration implements ConfigurationInterface
{
/**
* http://symfony.com/fr/doc/current/components/config/definition.html
* {@inheritDoc}
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
Expand All @@ -27,7 +28,7 @@ public function getConfigTreeBuilder()
->useAttributeAsKey('id', false)
->prototype('array')
->children()
->scalarNode('base_uri')->defaultValue("")->end()
->scalarNode('base_uri')->defaultValue('')->end()
->enumNode('redirect_handler')
->values(['curl', 'guzzle'])
->defaultValue('curl')
Expand All @@ -42,7 +43,7 @@ public function getConfigTreeBuilder()
->scalarNode('service')->cannotBeEmpty()->end()
->end()
->end()
->scalarNode('proxy')->defaultValue("")->end()
->scalarNode('proxy')->defaultValue('')->end()
->booleanNode('http_errors')->defaultValue(true)->end()
->floatNode('timeout')->defaultValue(5.0)->end()
->arrayNode('headers')
Expand Down
Loading

0 comments on commit 1da320f

Please sign in to comment.