1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 09:54:17 +02:00

Add php-cs-fixer

This commit is contained in:
Robin Appelman 2017-07-30 14:51:54 +02:00
commit 309ae17036
54 changed files with 4900 additions and 4106 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
.env
vendor
node_modules
.php_cs.cache

13
.php_cs.dist Normal file
View file

@ -0,0 +1,13 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__);
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'braces' => ['position_after_functions_and_oop_constructs' => 'same'],
])
->setFinder($finder);

View file

@ -20,3 +20,7 @@ phpunit:
.PHONY: test
tests: phpunit mocha
.PHONY: lint
lint:
vendor/bin/php-cs-fixer fix

View file

@ -19,6 +19,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^6.0",
"friendsofphp/php-cs-fixer": "^2.4"
}
}

2207
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,6 @@
<?php namespace Demostf\API\Controllers;
class BaseController {
protected function query($name, $default) {
$request = \Flight::request();
return isset($request->query[$name]) ? $request->query[$name] : $default;

View file

@ -9,8 +9,10 @@ class HeaderParser {
* @throws \InvalidArgumentException
*/
public function parseString(string $head): Header {
$info = @unpack('A8type/Iversion/Iprotocol/A260server/A260nick/A260map/A260game/fduration/Vticks/Vframes/Vsigon',
$head);
$info = @unpack(
'A8type/Iversion/Iprotocol/A260server/A260nick/A260map/A260game/fduration/Vticks/Vframes/Vsigon',
$head
);
if (!isset($info['type']) || $info['type'] !== 'HL2DEMO') {
throw new \InvalidArgumentException('Not an HL2 demo');
}

View file

@ -29,7 +29,8 @@ class UploadProvider extends BaseProvider {
private $demoSaver;
private $baseUrl;
public function __construct(Connection $db,
public function __construct(
Connection $db,
string $baseUrl,
HeaderParser $headerParser,
Parser $parser,

View file

@ -8,14 +8,14 @@ if (!getenv('DB_TYPE')) {
Dotenv::load(__DIR__ . '/../');
}
$connectionParams = array(
$connectionParams = [
'dbname' => getenv('DB_DATABASE'),
'user' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'host' => getenv('DB_HOST'),
'port' => getenv('DB_PORT'),
'driver' => getenv('DB_TYPE'),
);
];
if ($connectionParams['driver'] === 'pgsql') {
$connectionParams['driver'] = 'pdo_pgsql';
}

View file

@ -19,7 +19,6 @@ use Demostf\API\Test\TestCase;
class DemoSaverTest extends TestCase {
public function testSave() {
$steamId1 = $this->getSteamId('1234567', 'user1');
$steamId2 = $this->getSteamId('2345678', 'user2');
@ -52,7 +51,9 @@ class DemoSaverTest extends TestCase {
1
);
$parsed = new ParsedDemo(2, 3,
$parsed = new ParsedDemo(
2,
3,
[
new ChatMessage('user1', 12, 'msg1'),
new ChatMessage('user2', 13, 'msg2')

View file

@ -84,8 +84,10 @@ class UploadProviderTest extends TestCase {
private function rmdirr($dir) {
$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
$files = new \RecursiveIteratorIterator($it,
\RecursiveIteratorIterator::CHILD_FIRST);
$files = new \RecursiveIteratorIterator(
$it,
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $file) {
if ($file->isDir()) {
rmdir($file->getRealPath());
@ -198,7 +200,8 @@ class UploadProviderTest extends TestCase {
}
public function testUploadInvalidKey() {
$this->assertEquals('Invalid key',
$this->assertEquals(
'Invalid key',
$this->uploadProvider->upload('asdasd', 'RED', 'BLU', 'asdasd', 'asdas')
);
}
@ -242,13 +245,15 @@ class UploadProviderTest extends TestCase {
'b',
'p'
),
'test', 'test'
'test',
'test'
);
$steamId = $this->getSteamId('123', 'a');
$token = $this->userProvider->store($steamId);
$this->assertEquals('STV available at: http://example.com/' . $id,
$this->assertEquals(
'STV available at: http://example.com/' . $id,
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem')
);
}

View file

@ -9,14 +9,14 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
protected function getDatabaseConnection() {
if (!$this->database instanceof Connection) {
$connectionParams = array(
$connectionParams = [
'dbname' => getenv('DB_DATABASE'),
'user' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'host' => getenv('DB_HOST'),
'port' => getenv('DB_PORT'),
'driver' => getenv('DB_TYPE'),
);
];
if ($connectionParams['driver'] === 'pgsql') {
$connectionParams['driver'] = 'pdo_pgsql';
}
@ -62,5 +62,4 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
$closure($steamId);
return $steamId;
}
}