Skip to content

Commit

Permalink
Merge pull request #2 from chubbyphp/api-problem
Browse files Browse the repository at this point in the history
api-problem
  • Loading branch information
Dominik Zogg committed Apr 17, 2019
2 parents d2acc8e + 375fa74 commit 748bbc1
Show file tree
Hide file tree
Showing 135 changed files with 5,167 additions and 1,062 deletions.
15 changes: 10 additions & 5 deletions .gitignore
@@ -1,6 +1,11 @@
phpunit/
vendor/
composer.lock
.php_cs.cache

.DS_Store
.idea/
.php_cs.cache
.phpunit.result.cache
.vscode/
build/
composer.lock
composer.symlink
phpunit
phpunit.xml
vendor/
23 changes: 0 additions & 23 deletions .phan/config.php

This file was deleted.

6 changes: 6 additions & 0 deletions .scrutinizer.yml
@@ -1,4 +1,10 @@
build:
environment:
timezone: 'Europe/Zurich'
php:
version: '7.3'
ini:
'date.timezone': 'Europe/Zurich'
tests:
override:
-
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -27,4 +27,6 @@ before_script:
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest -n; fi;
- if [ "$dependencies" = "highest" ]; then composer update -n; fi;

script: vendor/bin/phpunit --coverage-text --verbose
script:
- vendor/bin/phpunit --coverage-text --verbose
- vendor/bin/phploc src --verbose
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2017 Dominik Zogg
Copyright (c) 2019 Dominik Zogg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -25,7 +25,7 @@ A simple http handler implementation for API.
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-api-http][1].

```sh
composer require chubbyphp/chubbyphp-api-http "~2.1"
composer require chubbyphp/chubbyphp-api-http "^3.0"
```

## Usage
Expand All @@ -38,7 +38,7 @@ composer require chubbyphp/chubbyphp-api-http "~2.1"

## Copyright

Dominik Zogg 2018
Dominik Zogg 2019

[1]: https://packagist.org/packages/chubbyphp/chubbyphp-api-http
[2]: doc/Error/Error.md
Expand Down
20 changes: 12 additions & 8 deletions composer.json
Expand Up @@ -10,23 +10,27 @@
}
],
"require": {
"php": "~7.0",
"chubbyphp/chubbyphp-deserialization": "~2.1",
"chubbyphp/chubbyphp-serialization": "~2.1",
"php": "^7.0",
"chubbyphp/chubbyphp-deserialization": "^2.1",
"chubbyphp/chubbyphp-serialization": "^2.1",
"psr/http-factory": "^1.0",
"psr/http-message": "~1.0"
"psr/http-message": "^1.0"
},
"require-dev": {
"chubbyphp/chubbyphp-mock": "^1.3.0",
"phpunit/phpunit": "^6.5.8|^7.4.3",
"pimple/pimple": "~3.0"
"chubbyphp/chubbyphp-mock": "^1.4",
"phploc/phploc": "^4.0|^5.0",
"phpunit/phpunit": "^6.5|^7.0|^8.0",
"pimple/pimple": "^3.1"
},
"autoload": {
"psr-4": { "Chubbyphp\\ApiHttp\\": "src/" }
},
"autoload-dev": {
"psr-4": { "Chubbyphp\\Tests\\ApiHttp\\": "tests/" }
},
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
"dev-master": "3.0-dev"
}
}
}
4 changes: 1 addition & 3 deletions phpunit.xml.dist
Expand Up @@ -7,11 +7,9 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="chubbyphp api http">
<testsuite name="chubbyphp framework">
<directory>./tests</directory>
</testsuite>
</testsuites>
Expand Down
67 changes: 67 additions & 0 deletions src/ApiProblem/AbstractApiProblem.php
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ApiProblem;

abstract class AbstractApiProblem implements ApiProblemInterface
{
/**
* @var string
*/
private $title;

/**
* @var string
*/
private $detail;

/**
* @var string|null
*/
private $instance;

/**
* @param string $title
* @param string|null $detail
* @param string|null $instance
*/
public function __construct(string $title, string $detail = null, string $instance = null)
{
$this->title = $title;
$this->detail = $detail;
$this->instance = $instance;
}

/**
* @return array
*/
public function getHeaders(): array
{
return [];
}

/**
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @return string|null
*/
public function getDetail()
{
return $this->detail;
}

/**
* @return string|null
*/
public function getInstance()
{
return $this->instance;
}
}
38 changes: 38 additions & 0 deletions src/ApiProblem/ApiProblemInterface.php
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ApiProblem;

interface ApiProblemInterface
{
/**
* @return int
*/
public function getStatus(): int;

/**
* @return array
*/
public function getHeaders(): array;

/**
* @return string
*/
public function getType(): string;

/**
* @return string
*/
public function getTitle(): string;

/**
* @return string|null
*/
public function getDetail();

/**
* @return string|null
*/
public function getInstance();
}
52 changes: 52 additions & 0 deletions src/ApiProblem/ClientError/BadRequest.php
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ApiProblem\ClientError;

use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;

final class BadRequest extends AbstractApiProblem
{
/**
* @var array[]
*/
private $invalidParameters = [];

/**
* @param array $invalidParameters
* @param string $title
* @param string|null $detail
* @param string|null $instance
*/
public function __construct(array $invalidParameters, string $title, string $detail = null, string $instance = null)
{
parent::__construct($title, $detail, $instance);

$this->invalidParameters = $invalidParameters;
}

/**
* @return int
*/
public function getStatus(): int
{
return 400;
}

/**
* @return string
*/
public function getType(): string
{
return 'https://tools.ietf.org/html/rfc2616#section-10.4.1';
}

/**
* @return array
*/
public function getInvalidParameters(): array
{
return $this->invalidParameters;
}
}
26 changes: 26 additions & 0 deletions src/ApiProblem/ClientError/Conflict.php
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ApiProblem\ClientError;

use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;

final class Conflict extends AbstractApiProblem
{
/**
* @return int
*/
public function getStatus(): int
{
return 409;
}

/**
* @return string
*/
public function getType(): string
{
return 'https://tools.ietf.org/html/rfc2616#section-10.4.10';
}
}
52 changes: 52 additions & 0 deletions src/ApiProblem/ClientError/ExpectationFailed.php
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ApiProblem\ClientError;

use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;

final class ExpectationFailed extends AbstractApiProblem
{
/**
* @var string[]
*/
private $failedExpectations = [];

/**
* @param string[] $failedExpectations
* @param string $title
* @param string|null $detail
* @param string|null $instance
*/
public function __construct(array $failedExpectations, string $title, string $detail = null, string $instance = null)
{
parent::__construct($title, $detail, $instance);

$this->failedExpectations = $failedExpectations;
}

/**
* @return int
*/
public function getStatus(): int
{
return 417;
}

/**
* @return string
*/
public function getType(): string
{
return 'https://tools.ietf.org/html/rfc2616#section-10.4.18';
}

/**
* @return string[]
*/
public function getFailedExpectations(): array
{
return $this->failedExpectations;
}
}
26 changes: 26 additions & 0 deletions src/ApiProblem/ClientError/FailedDependency.php
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ApiProblem\ClientError;

use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;

final class FailedDependency extends AbstractApiProblem
{
/**
* @return int
*/
public function getStatus(): int
{
return 424;
}

/**
* @return string
*/
public function getType(): string
{
return 'https://tools.ietf.org/html/rfc4918#section-11.4';
}
}

0 comments on commit 748bbc1

Please sign in to comment.