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:
parent
e00e6ece5f
commit
309ae17036
54 changed files with 4900 additions and 4106 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
|||
.env
|
||||
vendor
|
||||
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
|
||||
tests: phpunit mocha
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
vendor/bin/php-cs-fixer fix
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
}
|
||||
},
|
||||
"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;
|
||||
|
||||
|
||||
class BaseController {
|
||||
|
||||
protected function query($name, $default) {
|
||||
$request = \Flight::request();
|
||||
return isset($request->query[$name]) ? $request->query[$name] : $default;
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class Parser {
|
|||
$steamParts = explode(':', substr($steamId, 8));
|
||||
$steamId = $steamParts[0] + $steamParts[1] * 2 + 1197960265728;
|
||||
return '7656' . $steamId;
|
||||
} else if (preg_match('/^\[U:[0-1]:[0-9]+\]$/', $steamId)) {
|
||||
} elseif (preg_match('/^\[U:[0-1]:[0-9]+\]$/', $steamId)) {
|
||||
$steamParts = explode(':', substr($steamId, 3, -1));
|
||||
$steamId = $steamParts[0] + $steamParts[1] + 1197960265727;
|
||||
return '7656' . $steamId;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class BaseProvider {
|
|||
];
|
||||
if (isset($aliases[$table])) {
|
||||
return $aliases[$table];
|
||||
} else if (array_search($table, $rawNames) === false) {
|
||||
} elseif (array_search($table, $rawNames) === false) {
|
||||
return $table . 's';
|
||||
} else {
|
||||
return $table;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ $_SERVER['SCRIPT_NAME'] = '';
|
|||
|
||||
if ($_SERVER["REQUEST_URI"] === '/upload') {
|
||||
require __DIR__ . '/../src/public/upload.php';
|
||||
} else if ($_SERVER["REQUEST_URI"] === '/reset') {
|
||||
} elseif ($_SERVER["REQUEST_URI"] === '/reset') {
|
||||
// allow the api tests to reset the database
|
||||
/** @var \Demostf\API\Container $container */
|
||||
$container = require __DIR__ . '/../src/init.php';
|
||||
$connection = $container->getConnection();
|
||||
|
||||
clearDatabase($connection);
|
||||
} else if ($_SERVER["REQUEST_URI"] === '/testuser') {
|
||||
} elseif ($_SERVER["REQUEST_URI"] === '/testuser') {
|
||||
// allow the api tests to create a test user
|
||||
/** @var \Demostf\API\Container $container */
|
||||
$container = require __DIR__ . '/../src/init.php';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue