Skip to content

Commit

Permalink
refactor #5 Modernize code (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.0-dev branch.
labels: bc-break

Discussion
----------

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | 
| License       | MIT

Remove support for old PHP versions and modernize the code base. This will be a 2.0 release.

Commits
-------

011995f Remove deprecated code
33cf832 Add a Code-of-conduct
6a155be Modernize the code base
f98977c Update branch-alias
  • Loading branch information
sstok authored Aug 13, 2017
2 parents 2264be1 + f98977c commit b3c100d
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 292 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ core.autocrlf=lf
.gitignore export-ignore
.php_cs export-ignore
.scrutinizer.yml export-ignore
.styleci.yml export-ignore
.travis.yml export-ignore
.github export-ignore
phpspec.yml export-ignore
/spec export-ignore
/doc export-ignore
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/phpunit.xml
/composer.lock
*.phar
/vendor/
.php_cs.cache
59 changes: 44 additions & 15 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
<?php

return Symfony\CS\Config\Config::create()
->setUsingLinter(false)
// use SYMFONY_LEVEL:
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
// and extra fixers:
->fixers(array(
'ordered_use',
//'strict',
'strict_param',
'-psr0'
))
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->exclude(array('bin', 'spec'))
->in(__DIR__)
$header = <<<EOF
This file is part of the Rollerworks UriEncoder package.
(c) Sebastiaan Stok <[email protected]>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP70Migration' => true,
'@PHP71Migration' => true,
'array_syntax' => array('syntax' => 'short'),
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'header_comment' => ['header' => $header],
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'no_extra_consecutive_blank_lines' => ['continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
'no_short_echo_tag' => true,
'no_unreachable_default_argument_value' => false,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => false,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => false,
'phpdoc_annotation_without_dot' => true,
'phpdoc_no_empty_return' => false, // PHP 7 compatibility
'phpdoc_order' => true,
// This breaks for variable @var blocks
'phpdoc_to_comment' => false,
'phpdoc_var_without_name' => false,
'semicolon_after_instruction' => true,
'single_import_per_statement' => false,
'strict_comparison' => false,
'strict_param' => true,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in([__DIR__.'/src', __DIR__.'/spec'])
)
;
25 changes: 0 additions & 25 deletions .styleci.yml

This file was deleted.

19 changes: 1 addition & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@ branches:

matrix:
include:
# Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version
- php: hhvm-3.15
sudo: required
dist: trusty
group: edge
- php: 5.3
env: SKIP_OEL=true
- php: 5.4
env: SKIP_OEL=true
- php: 5.5
env: SKIP_OEL=true
- php: 5.6
- php: 7.0
- php: 7.1
fast_finish: true

Expand All @@ -29,11 +16,7 @@ cache:
- $HOME/.composer/cache

before_install:
# Matrix lines for OEL PHP versions are skipped for pull requests
- PHP=$TRAVIS_PHP_VERSION
- if [[ $SKIP_OEL && $TRAVIS_PULL_REQUEST != false ]]; then echo "Version ${PHP} is skipped for this pull request" && exit 0; fi
- if [[ ! $PHP = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi
- composer selfupdate --stable
- phpenv config-rm xdebug.ini || echo "xdebug not available"

install:
- composer install -o
Expand Down
1 change: 1 addition & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This project's code-of-conduct can be found at https://github.com/rollerworks/contributing/blob/master/CODE_OF_CONDUCT.md
13 changes: 12 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# ChangeLog

The changelog describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
The changelog describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

## v2.0.0

* Bump minimum version to PHP 7.1 (and removed support for HHVM).

* Removed the deprecated `CacheEncoderDecorator`.

* Added PHP strict types and return types to all interfaces
and classes.

* Classes are now marked final.

## v1.1.0

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
},
{
"name": "Community contributions",
"homepage": "https://github.com/Rollerworks/rollerworks-uri-encoder/contributors"
"homepage": "https://github.com/Rollerworks/uri-encoder/contributors"
}
],
"require": {
"php": ">=5.3.3"
"php": "^7.1"
},
"require-dev": {
"phpspec/phpspec": "~2.1"
"phpspec/phpspec": "^3.4.2"
},
"autoload": {
"psr-4": {
Expand All @@ -28,7 +28,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
"dev-master": "2.0-dev"
}
}
}
6 changes: 4 additions & 2 deletions spec/Encoder/Base64UriEncoderSpec.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Rollerworks UriEncoder Component package.
* This file is part of the Rollerworks UriEncoder package.
*
* (c) Sebastiaan Stok <[email protected]>
*
Expand All @@ -13,7 +15,7 @@

use PhpSpec\ObjectBehavior;

class Base64UriEncoderSpec extends ObjectBehavior
final class Base64UriEncoderSpec extends ObjectBehavior
{
public function it_is_initializable()
{
Expand Down
55 changes: 0 additions & 55 deletions spec/Encoder/CacheEncoderDecoratorSpec.php

This file was deleted.

8 changes: 5 additions & 3 deletions spec/Encoder/GZipCompressionDecoratorSpec.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Rollerworks UriEncoder Component package.
* This file is part of the Rollerworks UriEncoder package.
*
* (c) Sebastiaan Stok <[email protected]>
*
Expand All @@ -15,7 +17,7 @@
use Prophecy\Argument;
use Rollerworks\Component\UriEncoder\UriEncoderInterface;

class GZipCompressionDecoratorSpec extends ObjectBehavior
final class GZipCompressionDecoratorSpec extends ObjectBehavior
{
public function let(UriEncoderInterface $encoder)
{
Expand All @@ -25,7 +27,7 @@ public function let(UriEncoderInterface $encoder)
});

$encoder->decodeUri(Argument::any())->will(function ($data) {
return base64_decode($data[0]);
return base64_decode($data[0], true);
});

$this->beConstructedWith($encoder);
Expand Down
61 changes: 0 additions & 61 deletions src/CacheAdapterInterface.php

This file was deleted.

19 changes: 10 additions & 9 deletions src/Encoder/Base64UriEncoder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Rollerworks UriEncoder Component package.
* This file is part of the Rollerworks UriEncoder package.
*
* (c) Sebastiaan Stok <[email protected]>
*
Expand All @@ -20,26 +22,25 @@
*
* @author Sebastiaan Stok <[email protected]>
*/
class Base64UriEncoder implements UriEncoderInterface
final class Base64UriEncoder implements UriEncoderInterface
{
/**
* {@inheritdoc}
*/
public function encodeUri($data)
public function encodeUri(string $data): string
{
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}

/**
* {@inheritdoc}
*/
public function decodeUri($data)
public function decodeUri(string $data): ?string
{
$result = @base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT), true);
if (false !== $result) {
return $result;
try {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT), true) ?? null;
} catch (\Throwable $e) {
return null;
}

return;
}
}
Loading

0 comments on commit b3c100d

Please sign in to comment.