Skip to content

Commit

Permalink
Merge pull request #6 from LinioIT/php7
Browse files Browse the repository at this point in the history
[WIP] Migrated to PHP 7.
  • Loading branch information
klaussilveira committed Dec 3, 2015
2 parents 53cee45 + e04e6c8 commit 1427efe
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 458 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
build/
vendor/
bin/
composer.phar
phpunit.xml
cache.properties
coverage.xml
.php_cs.cache
composer.phar
composer.lock
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

before_install:
- travis_retry composer self-update
Expand All @@ -16,7 +12,4 @@ script:
- bin/phpunit --verbose

matrix:
allow_failures:
- php: hhvm
- php: 7.0
fast_finish: true
18 changes: 8 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
"type": "library",
"license": "BSD-3-Clause",
"require": {
"php": ">=5.4",
"nelmio/alice": "1.7.*",
"symfony/http-foundation": "~2.6",
"symfony/http-kernel": "~2.6",
"crell/api-problem": "~1.7",
"doctrine/collections": "~1.2"
"php": ">=7.0",
"psr/log": "~1.0",
"nelmio/alice": "~2.1",
"doctrine/collections": "~1.3"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
"symfony/form": "~2.6",
"symfony/routing": "~2.6",
"symfony/framework-bundle": "~2.6",
"phpunit/phpunit": "~5.0",
"symfony/form": "~2.7",
"symfony/routing": "~2.7",
"symfony/framework-bundle": "~2.7",
"doctrine/orm": "~2.5",
"gedmo/doctrine-extensions": "~2.3"
},
Expand Down
6 changes: 3 additions & 3 deletions src/Collection/FixedTypedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct($size, array $elements = [])
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function offsetSet($offset, $value)
{
Expand All @@ -53,7 +53,7 @@ public function get($key)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function offsetGet($offset)
{
Expand All @@ -80,7 +80,7 @@ protected function validateSize()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function matching(Criteria $criteria)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Collection/TypedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(array $elements = [])
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function offsetSet($offset, $value)
{
Expand All @@ -28,7 +28,7 @@ public function offsetSet($offset, $value)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function add($value)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/AccessDeniedHttpException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

Expand All @@ -10,10 +11,9 @@ class AccessDeniedHttpException extends HttpException
* @param string $message Error message
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
* @param string $detail Optional further details on the error
*/
public function __construct($message, $code = 0, $logLevel = LogLevel::WARNING, $detail = null)
public function __construct(string $message, int $code = 0, string $logLevel = LogLevel::WARNING)
{
parent::__construct($message, 403, $code, $logLevel, $detail);
parent::__construct($message, 403, $code, $logLevel);
}
}
6 changes: 3 additions & 3 deletions src/Exception/BadRequestHttpException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

Expand All @@ -10,10 +11,9 @@ class BadRequestHttpException extends HttpException
* @param string $message Error message
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
* @param string $detail Optional further details on the error
*/
public function __construct($message, $code = 0, $logLevel = LogLevel::WARNING, $detail = null)
public function __construct(string $message, int $code = 0, string $logLevel = LogLevel::WARNING)
{
parent::__construct($message, 400, $code, $logLevel, $detail);
parent::__construct($message, 400, $code, $logLevel);
}
}
8 changes: 3 additions & 5 deletions src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

Expand All @@ -16,16 +17,13 @@ class ErrorException extends \RuntimeException
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
*/
public function __construct($message, $code, $logLevel = LogLevel::ERROR)
public function __construct(string $message, int $code, string $logLevel = LogLevel::ERROR)
{
$this->logLevel = $logLevel;
parent::__construct($message, $code);
}

/**
* @return string
*/
public function getLogLevel()
public function getLogLevel(): string
{
return $this->logLevel;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/ForbiddenHttpException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

Expand All @@ -10,10 +11,9 @@ class ForbiddenHttpException extends HttpException
* @param string $message Error message
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
* @param string $detail Optional further details on the error
*/
public function __construct($message, $code = 0, $logLevel = LogLevel::WARNING, $detail = null)
public function __construct(string $message, int $code = 0, string $logLevel = LogLevel::WARNING)
{
parent::__construct($message, 403, $code, $logLevel, $detail);
parent::__construct($message, 403, $code, $logLevel);
}
}
42 changes: 5 additions & 37 deletions src/Exception/HttpException.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

use Crell\ApiProblem\ApiProblem;
use Psr\Log\LogLevel;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

/**
* HttpException aims to make it easier to handle public-facing
* errors in API's. It implements the draft-nottingham-http-problem-07
* RFC draft and abstracts it's usage by using the ApiProblem class.
*
* @link http://tools.ietf.org/html/draft-nottingham-http-problem-07
*/
class HttpException extends ErrorException implements HttpExceptionInterface
class HttpException extends ErrorException
{
/**
* @return int
Expand All @@ -25,52 +17,28 @@ class HttpException extends ErrorException implements HttpExceptionInterface
*/
protected $headers;

/**
* @var ApiProblem
*/
protected $apiProblem;

/**
* @param string $message Error message
* @param int $statusCode HTTP status code
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
* @param string $detail Optional further details on the error
* @param array $headers Optional header response information
*/
public function __construct($message, $statusCode, $code = 0, $logLevel = LogLevel::WARNING, $detail = null, array $headers = [])
public function __construct(string $message, int $statusCode, int $code = 0, string $logLevel = LogLevel::WARNING, array $headers = [])
{
$this->statusCode = $statusCode;
$this->headers = $headers;

$this->apiProblem = new ApiProblem($message, '#' . $code);
$this->apiProblem->setStatus($statusCode);
$this->apiProblem->setDetail($detail);

parent::__construct($message, $code, $logLevel);
}

/**
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return $this->statusCode;
}

/**
* @return array
*/
public function getHeaders()
public function getHeaders(): array
{
return $this->headers;
}

/**
* @return ApiProblem
*/
public function getApiProblem()
{
return $this->apiProblem;
}
}
6 changes: 3 additions & 3 deletions src/Exception/MethodNotAllowedHttpException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

Expand All @@ -10,10 +11,9 @@ class MethodNotAllowedHttpException extends HttpException
* @param string $message Error message
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
* @param string $detail Optional further details on the error
*/
public function __construct($message, $code = 0, $logLevel = LogLevel::WARNING, $detail = null)
public function __construct(string $message, int $code = 0, string $logLevel = LogLevel::WARNING)
{
parent::__construct($message, 405, $code, $logLevel, $detail);
parent::__construct($message, 405, $code, $logLevel);
}
}
6 changes: 3 additions & 3 deletions src/Exception/NotFoundHttpException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

Expand All @@ -10,10 +11,9 @@ class NotFoundHttpException extends HttpException
* @param string $message Error message
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
* @param string $detail Optional further details on the error
*/
public function __construct($message, $code = 0, $logLevel = LogLevel::WARNING, $detail = null)
public function __construct(string $message, int $code = 0, string $logLevel = LogLevel::WARNING)
{
parent::__construct($message, 404, $code, $logLevel, $detail);
parent::__construct($message, 404, $code, $logLevel);
}
}
6 changes: 3 additions & 3 deletions src/Exception/UnauthorizedHttpException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Linio\Exception;

Expand All @@ -10,10 +11,9 @@ class UnauthorizedHttpException extends HttpException
* @param string $message Error message
* @param int $code Internal code for the application error
* @param string $logLevel Log level of the error, from Psr\Log\LogLevel
* @param string $detail Optional further details on the error
*/
public function __construct($message, $code = 0, $logLevel = LogLevel::WARNING, $detail = null)
public function __construct(string $message, int $code = 0, string $logLevel = LogLevel::WARNING)
{
parent::__construct($message, 401, $code, $logLevel, $detail);
parent::__construct($message, 401, $code, $logLevel);
}
}
7 changes: 3 additions & 4 deletions src/Test/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Linio\Test;

use Nelmio\Alice\Fixtures\Loader;

abstract class UnitTestCase extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -11,7 +13,7 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase

public function loadFixtures($file)
{
$loader = new \Nelmio\Alice\Loader\Yaml();
$loader = new Loader();
$this->fixtures = $loader->load($file);
}

Expand All @@ -21,12 +23,9 @@ public function getMockForPdo($mockedMethods = [])
}
}

// @codingStandardsIgnoreStart
class PDOMock extends \PDO
{
public function __construct()
{
}
}
// @codingStandardsIgnoreEnd

Loading

0 comments on commit 1427efe

Please sign in to comment.