Skip to content

Commit aa61c8f

Browse files
Initial commit
0 parents  commit aa61c8f

10 files changed

+339
-0
lines changed

.gitattributes

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* text=auto
2+
3+
/tests export-ignore
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.travis.yml export-ignore
7+
/phpunit.xml.dist export-ignore
8+
/CONTRIBUTING.md export-ignore
9+
/README.md export-ignore

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
phpunit.xml
3+
vendor

.travis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: php
2+
3+
php:
4+
- 5.5.9
5+
- 5.5
6+
- 5.6
7+
- 7.0
8+
- hhvm
9+
10+
sudo: false
11+
12+
install:
13+
- travis_retry composer install --no-interaction --prefer-source
14+
15+
script:
16+
- if [ "$TRAVIS_PHP_VERSION" != "5.5.9" ] && [ "$TRAVIS_PHP_VERSION" != "5.5" ] && [ "$TRAVIS_PHP_VERSION" != "5.6" ]; then vendor/bin/phpunit; fi
17+
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi
18+
19+
after_script:
20+
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
21+
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi

CONTRIBUTING.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
CONTRIBUTING
2+
============
3+
4+
5+
Contributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests.
6+
7+
8+
## Guidelines
9+
10+
* Please follow the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) and [PHP-FIG Naming Conventions](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md).
11+
* Ensure that the current tests pass, and if you've added something new, add the tests where relevant.
12+
* Remember that we follow [SemVer](http://semver.org). If you are changing the behavior, or the public api, you may need to update the docs.
13+
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash](http://git-scm.com/book/en/Git-Tools-Rewriting-History) them before submitting.
14+
* You may also need to [rebase](http://git-scm.com/book/en/Git-Branching-Rebasing) to avoid merge conflicts.
15+
16+
17+
## Running Tests
18+
19+
You will need an install of [Composer](https://getcomposer.org) before continuing.
20+
21+
First, install the dependencies:
22+
23+
```bash
24+
$ composer install
25+
```
26+
27+
Then run PHPUnit:
28+
29+
```bash
30+
$ vendor/bin/phpunit
31+
```
32+
33+
If the test suite passes on your local machine you should be good to go.
34+
35+
When you make a pull request, the tests will automatically be run again by [Travis CI](https://travis-ci.org/) on multiple PHP versions and HHVM.
36+
37+
We also have StyleCI setup to automatically check and fix any code style issues.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Alt Three Services Limited
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# StyleCI SDK
2+
3+
The StyleCI PHP SDK.
4+
5+
6+
## Installation
7+
8+
Either [PHP](https://php.net) 5.5+ or [HHVM](http://hhvm.com) 3.6+ are required.
9+
10+
To get the latest version of StyleCI SDK, simply require the project using [Composer](https://getcomposer.org):
11+
12+
```bash
13+
$ composer require styleci/sdk
14+
```
15+
16+
Instead, you may of course manually update your require block and run `composer update` if you so choose:
17+
18+
```json
19+
{
20+
"require": {
21+
"styleci/sdk": "^1.0"
22+
}
23+
}
24+
```
25+
26+
27+
## Security
28+
29+
If you discover a security vulnerability within this package, please e-mail us at [email protected]. All security vulnerabilities will be promptly addressed.
30+
31+
32+
## License
33+
34+
Alt Three SDK is licensed under [The MIT License (MIT)](LICENSE).

composer.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "styleci/sdk",
3+
"description": "The StyleCI PHP SDK",
4+
"keywords": ["sdk", "alt-three", "styleci", "SDK", "Alt Three", "StyleCI"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "James Brooks",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Graham Campbell",
13+
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Joseph Cohen",
17+
"email": "[email protected]"
18+
}
19+
],
20+
"require": {
21+
"php": ">=5.5.9",
22+
"guzzlehttp/guzzle": "^6.1"
23+
},
24+
"require-dev": {
25+
"graham-campbell/testbench-core": "^1.1",
26+
"mockery/mockery": "^0.9.4",
27+
"phpunit/phpunit": "^4.8|^5.0"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"StyleCI\\SDK\\": "src/"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"StyleCI\\Tests\\SDK\\": "tests/"
37+
}
38+
},
39+
"config": {
40+
"preferred-install": "dist"
41+
},
42+
"extra": {
43+
"branch-alias": {
44+
"dev-master": "1.0-dev"
45+
}
46+
},
47+
"minimum-stability": "dev",
48+
"prefer-stable": true
49+
}

phpunit.xml.dist

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
beStrictAboutTestsThatDoNotTestAnything="true"
5+
beStrictAboutOutputDuringTests="true"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
convertErrorsToExceptions="true"
9+
convertNoticesToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
failOnRisky="true"
12+
failOnWarning="true"
13+
processIsolation="false"
14+
stopOnError="false"
15+
stopOnFailure="false"
16+
verbose="true"
17+
>
18+
<testsuites>
19+
<testsuite name="StyleCI SDK Test Suite">
20+
<directory suffix="Test.php">./tests</directory>
21+
</testsuite>
22+
</testsuites>
23+
<filter>
24+
<whitelist processUncoveredFilesFromWhitelist="true">
25+
<directory suffix=".php">./src</directory>
26+
</whitelist>
27+
</filter>
28+
</phpunit>

src/Client.php

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the StyleCI SDK.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace StyleCI\SDK;
13+
14+
use GuzzleHttp\Client as GuzzleClient;
15+
use GuzzleHttp\ClientInterface;
16+
17+
/**
18+
* This is the client class.
19+
*
20+
* @author Graham Campbell <[email protected]>
21+
*/
22+
class Client
23+
{
24+
/**
25+
* The base url.
26+
*
27+
* @var string
28+
*/
29+
const BASE_URL = 'https://api.styleci.io/';
30+
31+
/**
32+
* The guzzle client instance.
33+
*
34+
* @var \GuzzleHttp\ClientInterface
35+
*/
36+
protected $client;
37+
38+
/**
39+
* Create a new client instance.
40+
*
41+
* @param \GuzzleHttp\ClientInterface|null $client
42+
*
43+
* @return void
44+
*/
45+
public function __construct(ClientInterface $client = null)
46+
{
47+
$this->client = $client ?: new GuzzleClient(['base_uri' => static::BASE_URL, 'headers' => ['Accept' => 'application/json', 'User-Agent' => 'styleci-sdk/1.0']]);
48+
}
49+
50+
/**
51+
* Get the fixers.
52+
*
53+
* @return array
54+
*/
55+
public function fixers()
56+
{
57+
return $this->get('fixers');
58+
}
59+
60+
/**
61+
* Get the presets.
62+
*
63+
* @return array
64+
*/
65+
public function presets()
66+
{
67+
return $this->get('presets');
68+
}
69+
70+
/**
71+
* Send a get request, and parse the result as json.
72+
*
73+
* @return array
74+
*/
75+
protected function get($uri)
76+
{
77+
$response = $this->client->request('GET', $uri);
78+
79+
return json_decode($response->getBody(), true);
80+
}
81+
}

tests/ClientTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the StyleCI SDK.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace StyleCI\Tests\SDK;
13+
14+
use GrahamCampbell\TestBenchCore\MockeryTrait;
15+
use GuzzleHttp\ClientInterface;
16+
use Mockery;
17+
use PHPUnit_Framework_TestCase;
18+
use Psr\Http\Message\ResponseInterface;
19+
use StyleCI\SDK\Client;
20+
21+
/**
22+
* This is the client test class.
23+
*
24+
* @author Graham Campbell <[email protected]>
25+
*/
26+
class ClientTest extends PHPUnit_Framework_TestCase
27+
{
28+
use MockeryTrait;
29+
30+
public function testCanBeInstantiated()
31+
{
32+
$this->assertInstanceOf(Client::class, new Client());
33+
}
34+
35+
public function testCanGetFixers()
36+
{
37+
$client = new Client($mock = Mockery::mock(ClientInterface::class));
38+
39+
$mock->shouldReceive('request')->once()->with('GET', 'fixers')->andReturn($response = Mockery::mock(ResponseInterface::class));
40+
41+
$response->shouldReceive('getBody')->once()->andReturn('[{"name":"align_double_arrow","description":"Align double arrow symbols in consecutive lines.","risky":false,"conflict":"unalign_double_arrow","aliases":[]}]');
42+
43+
$this->assertSame([['name' => 'align_double_arrow', 'description' => 'Align double arrow symbols in consecutive lines.', 'risky' => false, 'conflict' => 'unalign_double_arrow', 'aliases' => []]], $client->fixers());
44+
}
45+
46+
public function testCanGetPresets()
47+
{
48+
$client = new Client($mock = Mockery::mock(ClientInterface::class));
49+
50+
$mock->shouldReceive('request')->once()->with('GET', 'presets')->andReturn($response = Mockery::mock(ResponseInterface::class));
51+
52+
$response->shouldReceive('getBody')->once()->andReturn('[{"title":"PSR1","name":"psr1","fixers":["encoding","full_opening_tag","psr4"]}]');
53+
54+
$this->assertSame([['title' => 'PSR1', 'name' => 'psr1', 'fixers' => ['encoding', 'full_opening_tag', 'psr4']]], $client->presets());
55+
}
56+
}

0 commit comments

Comments
 (0)