mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
Add php-cs-fixer
This commit is contained in:
parent
e00e6ece5f
commit
309ae17036
54 changed files with 4900 additions and 4106 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
||||||
.env
|
.env
|
||||||
vendor
|
vendor
|
||||||
node_modules
|
node_modules
|
||||||
|
.php_cs.cache
|
||||||
|
|
|
||||||
13
.php_cs.dist
Normal file
13
.php_cs.dist
Normal 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);
|
||||||
4
Makefile
4
Makefile
|
|
@ -20,3 +20,7 @@ phpunit:
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
tests: phpunit mocha
|
tests: phpunit mocha
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint:
|
||||||
|
vendor/bin/php-cs-fixer fix
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^6.0"
|
"phpunit/phpunit": "^6.0",
|
||||||
|
"friendsofphp/php-cs-fixer": "^2.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2207
composer.lock
generated
2207
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,8 +1,6 @@
|
||||||
<?php namespace Demostf\API\Controllers;
|
<?php namespace Demostf\API\Controllers;
|
||||||
|
|
||||||
|
|
||||||
class BaseController {
|
class BaseController {
|
||||||
|
|
||||||
protected function query($name, $default) {
|
protected function query($name, $default) {
|
||||||
$request = \Flight::request();
|
$request = \Flight::request();
|
||||||
return isset($request->query[$name]) ? $request->query[$name] : $default;
|
return isset($request->query[$name]) ? $request->query[$name] : $default;
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,10 @@ class HeaderParser {
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function parseString(string $head): Header {
|
public function parseString(string $head): Header {
|
||||||
$info = @unpack('A8type/Iversion/Iprotocol/A260server/A260nick/A260map/A260game/fduration/Vticks/Vframes/Vsigon',
|
$info = @unpack(
|
||||||
$head);
|
'A8type/Iversion/Iprotocol/A260server/A260nick/A260map/A260game/fduration/Vticks/Vframes/Vsigon',
|
||||||
|
$head
|
||||||
|
);
|
||||||
if (!isset($info['type']) || $info['type'] !== 'HL2DEMO') {
|
if (!isset($info['type']) || $info['type'] !== 'HL2DEMO') {
|
||||||
throw new \InvalidArgumentException('Not an HL2 demo');
|
throw new \InvalidArgumentException('Not an HL2 demo');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ class UploadProvider extends BaseProvider {
|
||||||
private $demoSaver;
|
private $demoSaver;
|
||||||
private $baseUrl;
|
private $baseUrl;
|
||||||
|
|
||||||
public function __construct(Connection $db,
|
public function __construct(
|
||||||
|
Connection $db,
|
||||||
string $baseUrl,
|
string $baseUrl,
|
||||||
HeaderParser $headerParser,
|
HeaderParser $headerParser,
|
||||||
Parser $parser,
|
Parser $parser,
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,14 @@ if (!getenv('DB_TYPE')) {
|
||||||
Dotenv::load(__DIR__ . '/../');
|
Dotenv::load(__DIR__ . '/../');
|
||||||
}
|
}
|
||||||
|
|
||||||
$connectionParams = array(
|
$connectionParams = [
|
||||||
'dbname' => getenv('DB_DATABASE'),
|
'dbname' => getenv('DB_DATABASE'),
|
||||||
'user' => getenv('DB_USERNAME'),
|
'user' => getenv('DB_USERNAME'),
|
||||||
'password' => getenv('DB_PASSWORD'),
|
'password' => getenv('DB_PASSWORD'),
|
||||||
'host' => getenv('DB_HOST'),
|
'host' => getenv('DB_HOST'),
|
||||||
'port' => getenv('DB_PORT'),
|
'port' => getenv('DB_PORT'),
|
||||||
'driver' => getenv('DB_TYPE'),
|
'driver' => getenv('DB_TYPE'),
|
||||||
);
|
];
|
||||||
if ($connectionParams['driver'] === 'pgsql') {
|
if ($connectionParams['driver'] === 'pgsql') {
|
||||||
$connectionParams['driver'] = 'pdo_pgsql';
|
$connectionParams['driver'] = 'pdo_pgsql';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ use Demostf\API\Test\TestCase;
|
||||||
|
|
||||||
class DemoSaverTest extends TestCase {
|
class DemoSaverTest extends TestCase {
|
||||||
public function testSave() {
|
public function testSave() {
|
||||||
|
|
||||||
$steamId1 = $this->getSteamId('1234567', 'user1');
|
$steamId1 = $this->getSteamId('1234567', 'user1');
|
||||||
$steamId2 = $this->getSteamId('2345678', 'user2');
|
$steamId2 = $this->getSteamId('2345678', 'user2');
|
||||||
|
|
||||||
|
|
@ -52,7 +51,9 @@ class DemoSaverTest extends TestCase {
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
|
||||||
$parsed = new ParsedDemo(2, 3,
|
$parsed = new ParsedDemo(
|
||||||
|
2,
|
||||||
|
3,
|
||||||
[
|
[
|
||||||
new ChatMessage('user1', 12, 'msg1'),
|
new ChatMessage('user1', 12, 'msg1'),
|
||||||
new ChatMessage('user2', 13, 'msg2')
|
new ChatMessage('user2', 13, 'msg2')
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,10 @@ class UploadProviderTest extends TestCase {
|
||||||
|
|
||||||
private function rmdirr($dir) {
|
private function rmdirr($dir) {
|
||||||
$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
|
$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
$files = new \RecursiveIteratorIterator($it,
|
$files = new \RecursiveIteratorIterator(
|
||||||
\RecursiveIteratorIterator::CHILD_FIRST);
|
$it,
|
||||||
|
\RecursiveIteratorIterator::CHILD_FIRST
|
||||||
|
);
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if ($file->isDir()) {
|
if ($file->isDir()) {
|
||||||
rmdir($file->getRealPath());
|
rmdir($file->getRealPath());
|
||||||
|
|
@ -198,7 +200,8 @@ class UploadProviderTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUploadInvalidKey() {
|
public function testUploadInvalidKey() {
|
||||||
$this->assertEquals('Invalid key',
|
$this->assertEquals(
|
||||||
|
'Invalid key',
|
||||||
$this->uploadProvider->upload('asdasd', 'RED', 'BLU', 'asdasd', 'asdas')
|
$this->uploadProvider->upload('asdasd', 'RED', 'BLU', 'asdasd', 'asdas')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -242,13 +245,15 @@ class UploadProviderTest extends TestCase {
|
||||||
'b',
|
'b',
|
||||||
'p'
|
'p'
|
||||||
),
|
),
|
||||||
'test', 'test'
|
'test',
|
||||||
|
'test'
|
||||||
);
|
);
|
||||||
|
|
||||||
$steamId = $this->getSteamId('123', 'a');
|
$steamId = $this->getSteamId('123', 'a');
|
||||||
$token = $this->userProvider->store($steamId);
|
$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')
|
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
protected function getDatabaseConnection() {
|
protected function getDatabaseConnection() {
|
||||||
if (!$this->database instanceof Connection) {
|
if (!$this->database instanceof Connection) {
|
||||||
$connectionParams = array(
|
$connectionParams = [
|
||||||
'dbname' => getenv('DB_DATABASE'),
|
'dbname' => getenv('DB_DATABASE'),
|
||||||
'user' => getenv('DB_USERNAME'),
|
'user' => getenv('DB_USERNAME'),
|
||||||
'password' => getenv('DB_PASSWORD'),
|
'password' => getenv('DB_PASSWORD'),
|
||||||
'host' => getenv('DB_HOST'),
|
'host' => getenv('DB_HOST'),
|
||||||
'port' => getenv('DB_PORT'),
|
'port' => getenv('DB_PORT'),
|
||||||
'driver' => getenv('DB_TYPE'),
|
'driver' => getenv('DB_TYPE'),
|
||||||
);
|
];
|
||||||
if ($connectionParams['driver'] === 'pgsql') {
|
if ($connectionParams['driver'] === 'pgsql') {
|
||||||
$connectionParams['driver'] = 'pdo_pgsql';
|
$connectionParams['driver'] = 'pdo_pgsql';
|
||||||
}
|
}
|
||||||
|
|
@ -62,5 +62,4 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
||||||
$closure($steamId);
|
$closure($steamId);
|
||||||
return $steamId;
|
return $steamId;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue