Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c5c687
commit 0e8789d
Showing
14 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
.gitattributes export-ignore | ||
.github export-ignore | ||
.gitignore export-ignore | ||
.github/ export-ignore | ||
tests/ export-ignore | ||
phpunit.xml export-ignore | ||
phpstan.neon export-ignore | ||
psalm.xml export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
laravel-tests: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
strategy: | ||
matrix: | ||
php-version: [7.4,8.0] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "${{ matrix.php-version }}" | ||
coverage: "pcov" | ||
|
||
- name: Install PHP dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | ||
|
||
- name: Run PHPUnit | ||
run: vendor/bin/phpunit --coverage-clover=coverage.xml | ||
|
||
- name: Upload coverage | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
files: ./coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: release-please | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
update_release_draft: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
|
||
steps: | ||
- uses: google-github-actions/release-please-action@v2 | ||
with: | ||
release-type: php | ||
- uses: actions/checkout@v2 | ||
if: ${{ steps.release.outputs.release_created }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: static analysis | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
phpstan: | ||
name: PHPStan | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
strategy: | ||
matrix: | ||
php-version: [7.4,8.0] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "${{ matrix.php-version }}" | ||
coverage: none | ||
extensions: mbstring | ||
tools: composer | ||
|
||
- name: Download dependencies | ||
run: composer update --no-interaction --no-progress | ||
|
||
- name: Download PHPStan | ||
run: composer bin phpstan require phpstan/phpstan | ||
|
||
- name: Execute PHPStan | ||
run: vendor/bin/phpstan analyze --no-progress | ||
|
||
psalm: | ||
name: Psalm | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
strategy: | ||
matrix: | ||
php-version: [7.4,8.0] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "${{ matrix.php-version }}" | ||
coverage: none | ||
extensions: mbstring | ||
tools: composer | ||
|
||
- name: Download dependencies | ||
run: composer update --no-interaction --no-progress | ||
|
||
- name: Download Psalm | ||
run: composer bin psalm require vimeo/psalm | ||
|
||
- name: Execute Psalm | ||
run: vendor/bin/psalm --no-progress --shepherd --output-format=github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/vendor/ | ||
/vendor-bin/ | ||
node_modules/ | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# Laravel 4 specific | ||
bootstrap/compiled.php | ||
app/storage/ | ||
|
||
# Laravel 5 & Lumen specific | ||
public/storage | ||
public/hot | ||
|
||
# Laravel 5 & Lumen specific with changed public path | ||
public_html/storage | ||
public_html/hot | ||
|
||
storage/*.key | ||
.env | ||
Homestead.yaml | ||
Homestead.json | ||
/.vagrant | ||
.phpunit.result.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,40 @@ | ||
# resolve-uri | ||
|
||
[![Latest Stable Version](https://img.shields.io/github/v/release/brokeyourbike/resolve-uri)](https://github.com/brokeyourbike/resolve-uri/releases) | ||
[![Total Downloads](https://poser.pugx.org/brokeyourbike/resolve-uri/downloads)](https://packagist.org/packages/brokeyourbike/resolve-uri) | ||
[![License: MPL-2.0](https://img.shields.io/badge/license-MPL--2.0-purple.svg)](https://github.com/brokeyourbike/resolve-uri/blob/main/LICENSE) | ||
|
||
[![ci](https://github.com/brokeyourbike/resolve-uri/actions/workflows/ci.yml/badge.svg)](https://github.com/brokeyourbike/resolve-uri/actions/workflows/ci.yml) | ||
[![codecov](https://codecov.io/gh/brokeyourbike/resolve-uri/branch/main/graph/badge.svg?token=ImcgnxzGfc)](https://codecov.io/gh/brokeyourbike/resolve-uri) | ||
[![Type Coverage](https://shepherd.dev/github/brokeyourbike/resolve-uri/coverage.svg)](https://shepherd.dev/github/brokeyourbike/resolve-uri) | ||
|
||
Trait for resolving URI | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require brokeyourbike/resolve-uri | ||
``` | ||
|
||
## Usage | ||
|
||
```php | ||
use BrokeYourBike\ResolveUri\ResolveUriTrait; | ||
|
||
class APIClient | ||
{ | ||
use ResolveUriTrait; | ||
|
||
public function fetchProduct(string $productId) | ||
{ | ||
$uri = $this->fetchUriFor('https://example.com', "products/{$productId}"); | ||
} | ||
} | ||
``` | ||
|
||
## Why | ||
|
||
Resolve URI when `base_url` is not defined in HTTP client. | ||
|
||
## License | ||
[Mozilla Public License v2.0](https://github.com/brokeyourbike/resolve-uri/blob/main/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "brokeyourbike/resolve-uri", | ||
"description": "Trait for resolving URI", | ||
"type": "library", | ||
"license": "MPL-2.0", | ||
"autoload": { | ||
"psr-4": { | ||
"BrokeYourBike\\ResolveUri\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"BrokeYourBike\\Tests\\ResolveUri\\": "tests/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Ivan Stasiuk", | ||
"email": "brokeyourbike@gmail.com", | ||
"homepage": "https://github.com/brokeyourbike" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": "^7.4|^8.0", | ||
"psr/http-message": "^1.0", | ||
"guzzlehttp/psr7": "^2" | ||
}, | ||
"require-dev": { | ||
"bamarni/composer-bin-plugin": "^1.4", | ||
"phpunit/phpunit": "^9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
parameters: | ||
checkMissingIterableValueType: false | ||
level: max | ||
paths: | ||
- src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit | ||
colors="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
bootstrap="vendor/autoload.php" | ||
> | ||
<testsuites> | ||
<testsuite name="HTTP Client Test Suite"> | ||
<directory suffix=".php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
totallyTyped="true" | ||
resolveFromConfigFile="false" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" | ||
> | ||
<projectFiles> | ||
<directory name="src" /> | ||
<ignoreFiles> | ||
<directory name="vendor" /> | ||
<directory name="vendor-bin" /> | ||
</ignoreFiles> | ||
</projectFiles> | ||
</psalm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ResolveUri; | ||
|
||
use GuzzleHttp\Psr7\Utils; | ||
use GuzzleHttp\Psr7\UriResolver; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
trait ResolveUriTrait | ||
{ | ||
/** | ||
* @return \Psr\Http\Message\UriInterface | ||
*/ | ||
public function resolveUriFor(string $baseUri, string $uri): \Psr\Http\Message\UriInterface | ||
{ | ||
$baseUri = Utils::uriFor($baseUri); | ||
$uri = Utils::uriFor($uri); | ||
|
||
return UriResolver::resolve($baseUri, $uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\Tests\ResolveUri; | ||
|
||
use BrokeYourBike\ResolveUri\ResolveUriTrait; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class ApiClientFixture | ||
{ | ||
use ResolveUriTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\Tests\ResolveUri; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use BrokeYourBike\ResolveUri\ResolveUriTrait; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class ResolveUriTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_uses_json_request_result_trait(): void | ||
{ | ||
$usedTraits = class_uses(ApiClientFixture::class); | ||
|
||
$this->assertArrayHasKey(ResolveUriTrait::class, $usedTraits); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_resolve_uri() | ||
{ | ||
$apiClient = new ApiClientFixture(); | ||
|
||
$uri = $apiClient->resolveUriFor('https://example.com', 'hello-world'); | ||
|
||
$this->assertInstanceOf(\Psr\Http\Message\UriInterface::class, $uri); | ||
$this->assertSame('https://example.com/hello-world', (string) $uri); | ||
} | ||
} |