Skip to content

[10.0] Switch to PSR-17 and PSR-18 #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
preset: psr2
preset: psr12

enabled:
- phpdoc_indent
- phpdoc_scalar

disabled:
- blank_line_after_opening_tag
- concat_with_spaces
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
language: php

dist: bionic

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

matrix:
# test latest PHP stable version with lowest dependencies and phpstan static analysis
include:
- php: 7.3
env: STATIC_ANALYSIS=yes
- php: 7.4
name: phpstan
script:
- vendor/bin/phpstan analyse --no-progress

before_script:
- travis_retry composer self-update
install:
- travis_retry composer update --no-interaction ${COMPOSER_FLAGS}
- if [ "$STATIC_ANALYSIS" != "" ]; then curl -L https://github.com/phpstan/phpstan/releases/download/0.8/phpstan.phar -o phpstan.phar; fi;

script:
- vendor/bin/phpunit --verbose --coverage-text
- if [ "$STATIC_ANALYSIS" != "" ]; then php phpstan.phar analyse --level=4 lib; fi;
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,39 @@ Based on [php-github-api](https://github.com/m4tthumphrey/php-github-api) and co
Installation
------------

Via [composer](https://getcomposer.org)
Via [Composer](https://getcomposer.org). You will also need to install packages that "provide" [`psr/http-client-implementation`](https://packagist.org/providers/psr/http-client-implementation) and [`psr/http-factory-implementation`](https://packagist.org/providers/psr/http-factory-implementation).

### PHP 7.1+:

```bash
composer require m4tthumphrey/php-gitlab-api php-http/guzzle6-adapter:^1.0
composer require m4tthumphrey/php-gitlab-api:^10.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0
```

Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io).
### PHP 7.2+:

You can visit [HTTPlug for library users](http://docs.php-http.org/en/latest/httplug/users.html) to get more information about installing HTTPlug related packages.
```bash
composer require m4tthumphrey/php-gitlab-api:^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
```

Versioning
----------
### Laravel 6+:

Depending on your Gitlab server version, you must choose the right version of this library.
Please refer to the following table to pick the right one.
```bash
composer require graham-campbell/gitlab:^4.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
```

### Symfony 4.4:

```bash
composer require zeichen32/gitlabapibundle:^5.0 symfony/http-client:^4.4 nyholm/psr7:^1.3
```

|Version|Gitlab API Version|Gitlab Version|
|-------|------------------|--------------|
|9.x | V4 | >= 9.0 |
|8.x | V3 | < 9.5 |
### Symfony 5:

```bash
composer require zeichen32/gitlabapibundle:^5.0 symfony/http-client:^5.0 nyholm/psr7:^1.3
```

We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). You can visit [HTTPlug for library users](https://docs.php-http.org/en/latest/httplug/users.html) to get more information about installing HTTPlug related packages. [graham-campbell/gitlab](https://github.com/GrahamCampbell/Laravel-GitLab) is by [Graham Campbell](https://github.com/GrahamCampbell) and [zeichen32/gitlabapibundle](https://github.com/Zeichen32/GitLabApiBundle) is by [Jens Averkamp](https://github.com/Zeichen32).

General API Usage
-----------------
Expand Down Expand Up @@ -67,8 +80,6 @@ $issues = $pager->fetchAll($client->api('issues'),'all',[null, ['state' => 'clos

```



Model Usage
-----------

Expand Down Expand Up @@ -98,18 +109,9 @@ $issue = $project->createIssue('This does not work.', array(
$issue->close();
```

You get the idea! Take a look around ([API methods](https://github.com/m4tthumphrey/php-gitlab-api/tree/master/lib/Gitlab/Api),
[models](https://github.com/m4tthumphrey/php-gitlab-api/tree/master/lib/Gitlab/Model)) and please feel free to report any bugs.

Framework Integrations
----------------------
- **Symfony** - https://github.com/Zeichen32/GitLabApiBundle
- **Laravel** - https://github.com/GrahamCampbell/Laravel-GitLab

If you have integrated GitLab into a popular PHP framework, let us know!
You get the idea! Take a look around ([API methods](https://github.com/m4tthumphrey/php-gitlab-api/tree/master/lib/Gitlab/Api), [models](https://github.com/m4tthumphrey/php-gitlab-api/tree/master/lib/Gitlab/Model)) and please feel free to report any bugs. If you have integrated GitLab into a popular PHP framework, let us know!

Contributing
------------

There are many parts of Gitlab that I have not added to this as it was originally created for personal use, hence the
lack of tests. Feel free to fork and add new functionality and tests, I'll gladly accept decent pull requests.
There are many parts of Gitlab that I have not added to this as it was originally created for personal use, hence the lack of tests. Feel free to fork and add new functionality and tests, I'll gladly accept decent pull requests.
103 changes: 55 additions & 48 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
{
"name": "m4tthumphrey/php-gitlab-api",
"type": "library",
"description": "GitLab API client",
"homepage": "https://github.com/m4tthumphrey/php-gitlab-api",
"keywords": ["gitlab", "api"],
"license": "MIT",
"authors": [
{
"name": "Matt Humphrey",
"homepage": "http://m4tt.io"
},
{
"name": "KnpLabs Team",
"homepage": "http://knplabs.com"
},
{
"name": "Thibault Duplessis",
"email": "thibault.duplessis@gmail.com",
"homepage": "http://ornicar.github.com"
}
],
"require": {
"php": "^5.6 || ^7.0",
"ext-xml": "*",
"php-http/client-common": "^1.6 || ^2.0",
"php-http/client-implementation": "^1.0",
"php-http/discovery": "^1.2",
"php-http/httplug": "^1.1 || ^2.0",
"php-http/multipart-stream-builder": "^1.0",
"symfony/options-resolver": "^2.6 || ^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.2",
"php-http/guzzle6-adapter": "^1.0 || ^2.0",
"php-http/mock-client": "^1.2",
"phpunit/phpunit": "^5.7.27 || ^7.5.15"
},
"autoload": {
"psr-4": { "Gitlab\\": "lib/Gitlab/" }
},
"autoload-dev": {
"psr-4": { "Gitlab\\Tests\\": "test/Gitlab/Tests/" }
},
"extra": {
"branch-alias": {
"dev-master": "9.17-dev"
}
}
"name": "m4tthumphrey/php-gitlab-api",
"type": "library",
"description": "GitLab API client",
"homepage": "https://github.com/m4tthumphrey/php-gitlab-api",
"keywords": ["gitlab", "api"],
"license": "MIT",
"authors": [
{
"name": "Matt Humphrey",
"homepage": "http://m4tt.io"
},
{
"name": "KnpLabs Team",
"homepage": "http://knplabs.com"
},
{
"name": "Thibault Duplessis",
"email": "thibault.duplessis@gmail.com",
"homepage": "http://ornicar.github.com"
}
],
"require": {
"php": "^7.1",
"ext-xml": "*",
"php-http/client-common": "^2.2",
"php-http/cache-plugin": "^1.7",
"php-http/discovery": "^1.9",
"php-http/httplug": "^2.1",
"php-http/multipart-stream-builder": "^1.1",
"psr/cache": "^1.0",
"psr/http-client-implementation": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0",
"symfony/options-resolver": "^3.4 || ^4.0 || ^5.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.5.2",
"php-http/guzzle6-adapter": "^2.0.1",
"http-interop/http-factory-guzzle": "^1.0",
"phpstan/phpstan": "^0.12.32",
"phpstan/extension-installer": "^1.0.4",
"phpstan/phpstan-deprecation-rules": "^0.12.4",
"phpunit/phpunit": "^7.5.15"
},
"autoload": {
"psr-4": { "Gitlab\\": "lib/Gitlab/" }
},
"autoload-dev": {
"psr-4": { "Gitlab\\Tests\\": "test/Gitlab/Tests/" }
},
"extra": {
"branch-alias": {
"dev-master": "10.0-dev"
}
}
}
14 changes: 7 additions & 7 deletions lib/Gitlab/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use Gitlab\HttpClient\Message\QueryStringBuilder;
use Gitlab\HttpClient\Message\ResponseMediator;
use Gitlab\Tests\HttpClient\Message\QueryStringBuilderTest;
use Http\Discovery\StreamFactoryDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Message\MultipartStream\MultipartStreamBuilder;
use Http\Message\StreamFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand All @@ -28,18 +28,18 @@ abstract class AbstractApi implements ApiInterface
protected $client;

/**
* @var StreamFactory
* @var StreamFactoryInterface
*/
private $streamFactory;

/**
* @param Client $client
* @param StreamFactory|null $streamFactory
* @param StreamFactoryInterface|null $streamFactory
*/
public function __construct(Client $client, StreamFactory $streamFactory = null)
public function __construct(Client $client, StreamFactoryInterface $streamFactory = null)
{
$this->client = $client;
$this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find();
$this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory();
}

/**
Expand Down Expand Up @@ -248,7 +248,7 @@ private function preparePath($path, array $parameters = [])
}

/**
* @param $file
* @param string $file
*
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions lib/Gitlab/Api/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function transfer($group_id, $project_id)
}

/**
* @param integer $id
* @param integer|null $user_id
* @param int $id
* @param int|null $user_id
* @param array $parameters
* @return mixed
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ public function removeMember($group_id, $user_id)
}

/**
* @param $id
* @param int $id
* @param array $parameters (
*
* @var bool $archived Limit by archived status.
Expand Down
10 changes: 5 additions & 5 deletions lib/Gitlab/Api/Issues.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ public function awardEmoji($project_id, $issue_iid)
}

/**
* @param int $project_id
* @param int $issue_iid
* @return mixed
*/
* @param int $project_id
* @param int $issue_iid
* @return mixed
*/
public function closedByMergeRequests($project_id, $issue_iid)
{
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_iid)).'/closed_by');
Expand All @@ -319,7 +319,7 @@ public function showParticipants($project_id, $issue_iid)
{
return $this->get($this->getProjectPath($project_id, 'issues/' .$this->encodePath($issue_iid)).'/participants');
}

/**
* {@inheritDoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Gitlab/Api/MergeRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function update($project_id, $mr_id, array $params)
/**
* @param int $project_id
* @param int $mr_id
* @param string $message
* @param string|array $message
* @return mixed
*/
public function merge($project_id, $mr_id, $message = null)
Expand Down
2 changes: 1 addition & 1 deletion lib/Gitlab/Api/ProjectNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function all(array $parameters = [])
}

/**
* @param integer|string $namespace_id
* @param int|string $namespace_id
* @return mixed
*/
public function show($namespace_id)
Expand Down
Loading