Formatting to follow PSR-12

main
Igor Scheller 5 years ago
parent b878740f80
commit 68afc74b03

@ -70,13 +70,24 @@ test:
- apk add ${PHPIZE_DEPS} && pecl install xdebug && docker-php-ext-enable xdebug - apk add ${PHPIZE_DEPS} && pecl install xdebug && docker-php-ext-enable xdebug
- curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer - curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer
- cp -R tests/ phpunit.xml "${DOCROOT}" - cp -R tests/ phpunit.xml "${DOCROOT}"
- HOMEDIR=$(pwd) - HOMEDIR=$PWD
- cd "${DOCROOT}" - cd "${DOCROOT}"
- composer --no-ansi install - composer --no-ansi install
- ./bin/migrate - ./bin/migrate
script: script:
- vendor/bin/phpunit -v --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml" - ./vendor/bin/phpunit -v --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
- bin/migrate down - ./bin/migrate down
check-style:
image: ${TEST_IMAGE}
stage: test
before_script:
- curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer
- cp -R tests/ "${DOCROOT}"
- cd "${DOCROOT}"
- composer --no-ansi install
script:
- ./vendor/bin/phpcs --no-colors --basepath="$PWD" -p --standard=PSR12 config/ db/ public/index.php src/ tests/
release-image: release-image:
<<: *docker_definition <<: *docker_definition

@ -196,5 +196,9 @@ For more information on how to use it call `./bin/migrate help`
### Translation ### Translation
We use gettext. You may use POEdit to extract new texts from the sourcecode. Please config POEdit to extract also the twig template files using the following settings: https://gist.github.com/jlambe/a868d9b63d70902a12254ce47069d0e6 We use gettext. You may use POEdit to extract new texts from the sourcecode. Please config POEdit to extract also the twig template files using the following settings: https://gist.github.com/jlambe/a868d9b63d70902a12254ce47069d0e6
### Codestyle ### Code style
Please ensure that your pull requests follow [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/). Please ensure that your pull requests follows the [PSR-12](http://www.php-fig.org/psr/psr-12/) coding style guide.
You can check that by running
```php
vendor/bin/phpcs --standard=PSR12 config/ db/ public/index.php src/ tests/
```

@ -44,6 +44,7 @@
"dms/phpunit-arraysubset-asserts": "^0.1.0", "dms/phpunit-arraysubset-asserts": "^0.1.0",
"filp/whoops": "^2.3", "filp/whoops": "^2.3",
"phpunit/phpunit": "^8.1", "phpunit/phpunit": "^8.1",
"squizlabs/php_codesniffer": "^3.5",
"symfony/var-dumper": "^4.3" "symfony/var-dumper": "^4.3"
}, },
"autoload": { "autoload": {

@ -47,8 +47,7 @@ class ImportInstallSql extends Migration
/** /**
* Reverse the migration * Reverse the migration
*/ */
public public function down()
function down()
{ {
$this->schema->getConnection()->statement('SET FOREIGN_KEY_CHECKS=0;'); $this->schema->getConnection()->statement('SET FOREIGN_KEY_CHECKS=0;');

@ -18,7 +18,8 @@ class FixOldTables extends Migration
[ [
'User' => 'CreateDate', 'User' => 'CreateDate',
'NewsComments' => 'Datum', 'NewsComments' => 'Datum',
] as $table => $column) { ] as $table => $column
) {
if (!$this->schema->hasTable($table)) { if (!$this->schema->hasTable($table)) {
continue; continue;
} }

@ -83,8 +83,10 @@ class CreateUsersTables extends Migration
}); });
if ($this->schema->hasTable('User')) { if ($this->schema->hasTable('User')) {
$emptyDates = ['0000-00-00 00:00:00', '0001-01-01 00:00:00', '1000-01-01 00:00:00'];
/** @var stdClass[] $users */ /** @var stdClass[] $users */
$users = $this->schema->getConnection()->table('User')->get(); $users = $this->schema->getConnection()->table('User')->get();
foreach ($users as $data) { foreach ($users as $data) {
$user = new User([ $user = new User([
'name' => $data->Nick, 'name' => $data->Nick,
@ -94,10 +96,7 @@ class CreateUsersTables extends Migration
'last_login_at' => Carbon::createFromTimestamp($data->lastLogIn), 'last_login_at' => Carbon::createFromTimestamp($data->lastLogIn),
]); ]);
$user->setAttribute('id', $data->UID); $user->setAttribute('id', $data->UID);
if (!in_array( if (!in_array($data->CreateDate, $emptyDates)) {
$data->CreateDate,
['0000-00-00 00:00:00', '0001-01-01 00:00:00', '1000-01-01 00:00:00']
)) {
$user->setAttribute('created_at', new Carbon($data->CreateDate)); $user->setAttribute('created_at', new Carbon($data->CreateDate));
} }
$user->save(); $user->save();
@ -114,8 +113,12 @@ class CreateUsersTables extends Migration
'first_name' => $data->Vorname ?: null, 'first_name' => $data->Vorname ?: null,
'last_name' => $data->Name ?: null, 'last_name' => $data->Name ?: null,
'shirt_size' => $data->Size ?: null, 'shirt_size' => $data->Size ?: null,
'planned_arrival_date' => $data->planned_arrival_date ? Carbon::createFromTimestamp($data->planned_arrival_date) : null, 'planned_arrival_date' => $data->planned_arrival_date
'planned_departure_date' => $data->planned_departure_date ? Carbon::createFromTimestamp($data->planned_departure_date) : null, ? Carbon::createFromTimestamp($data->planned_arrival_date)
: null,
'planned_departure_date' => $data->planned_departure_date
? Carbon::createFromTimestamp($data->planned_departure_date)
: null,
]); ]);
$personalData->user() $personalData->user()
->associate($user) ->associate($user)
@ -181,7 +184,7 @@ class CreateUsersTables extends Migration
$table->string('DECT', 5)->nullable(); $table->string('DECT', 5)->nullable();
$table->string('Handy', 40)->nullable(); $table->string('Handy', 40)->nullable();
$table->string('email', 123)->nullable(); $table->string('email', 123)->nullable();
$table->boolean('email_shiftinfo')->default(false)->comment('User wants to be informed by mail about changes in his shifts'); $table->boolean('email_shiftinfo')->default(false);
$table->string('jabber', 200)->nullable(); $table->string('jabber', 200)->nullable();
$table->string('Size', 4)->nullable(); $table->string('Size', 4)->nullable();
$table->string('Passwort', 128)->nullable(); $table->string('Passwort', 128)->nullable();
@ -244,8 +247,12 @@ class CreateUsersTables extends Migration
'api_key' => $user->api_key, 'api_key' => $user->api_key,
'got_voucher' => $state->got_voucher, 'got_voucher' => $state->got_voucher,
'arrival_date' => $state->arrival_date ? $state->arrival_date->getTimestamp() : null, 'arrival_date' => $state->arrival_date ? $state->arrival_date->getTimestamp() : null,
'planned_arrival_date' => $personal->planned_arrival_date ? $personal->planned_arrival_date->getTimestamp() : null, 'planned_arrival_date' => $personal->planned_arrival_date
'planned_departure_date' => $personal->planned_departure_date ? $personal->planned_departure_date->getTimestamp() : null, ? $personal->planned_arrival_date->getTimestamp()
: null,
'planned_departure_date' => $personal->planned_departure_date
? $personal->planned_departure_date->getTimestamp()
: null,
'email_by_human_allowed' => $settings->email_human, 'email_by_human_allowed' => $settings->email_human,
]); ]);
} }

@ -24,14 +24,16 @@ trait ChangesReferences
$table->dropForeign($reference->constraint); $table->dropForeign($reference->constraint);
}); });
$this->schema->table($reference->table, $this->schema->table(
$reference->table,
function (Blueprint $table) use ($reference, $targetTable, $targetColumn, $type) { function (Blueprint $table) use ($reference, $targetTable, $targetColumn, $type) {
$table->{$type}($reference->column)->change(); $table->{$type}($reference->column)->change();
$table->foreign($reference->column) $table->foreign($reference->column)
->references($targetColumn)->on($targetTable) ->references($targetColumn)->on($targetTable)
->onDelete('cascade'); ->onDelete('cascade');
}); }
);
} }
} }

@ -2754,9 +2754,7 @@ msgid "Development Platform"
msgstr "Entwicklerplattform" msgstr "Entwicklerplattform"
#: src/Middleware/LegacyMiddleware.php #: src/Middleware/LegacyMiddleware.php
msgid "" msgid "page.404.text"
"This page could not be found or you don't have permission to view it. You "
"probably have to sign in or register in order to gain access!"
msgstr "" msgstr ""
"Diese Seite existiert nicht oder Du hast keinen Zugriff. Melde Dich an um " "Diese Seite existiert nicht oder Du hast keinen Zugriff. Melde Dich an um "
"Zugriff zu erhalten!" "Zugriff zu erhalten!"

@ -25,6 +25,11 @@ msgstr ""
msgid "form.submit" msgid "form.submit"
msgstr "Submit" msgstr "Submit"
msgid "page.404.text"
msgstr ""
"This page could not be found or you don't have permission to view it. "
"You probably have to sign in or register in order to gain access!"
msgid "credits.credit" msgid "credits.credit"
msgstr "" msgstr ""
"The original engelsystem was written by " "The original engelsystem was written by "

@ -137,10 +137,12 @@ class MetricsEngine implements EngineInterface
} }
/** /**
* Does nothing as shared data will onyly result in unexpected behaviour * Does nothing as shared data will only result in unexpected behaviour
* *
* @param string|mixed[] $key * @param string|mixed[] $key
* @param mixed $value * @param mixed $value
*/ */
public function share($key, $value = null) { } public function share($key, $value = null)
{
}
} }

@ -74,7 +74,7 @@ class PasswordResetController extends BaseController
/** @var User $user */ /** @var User $user */
$user = User::whereEmail($data['email'])->first(); $user = User::whereEmail($data['email'])->first();
if ($user) { if ($user) {
$reset = (new PasswordReset)->findOrNew($user->id); $reset = (new PasswordReset())->findOrNew($user->id);
$reset->user_id = $user->id; $reset->user_id = $user->id;
$reset->token = md5(random_bytes(64)); $reset->token = md5(random_bytes(64));
$reset->save(); $reset->save();
@ -120,8 +120,10 @@ class PasswordResetController extends BaseController
]); ]);
if ($data['password'] !== $data['password_confirmation']) { if ($data['password'] !== $data['password_confirmation']) {
$this->session->set('errors', $this->session->set(
array_merge($this->session->get('errors', []), ['validation.password.confirmed'])); 'errors',
array_merge($this->session->get('errors', []), ['validation.password.confirmed'])
);
return $this->showView('pages/password/reset-form'); return $this->showView('pages/password/reset-form');
} }

@ -11,8 +11,11 @@ use Illuminate\Support\Str;
class Migrate class Migrate
{ {
const UP = 'up'; /** @var string */
const DOWN = 'down'; public const UP = 'up';
/** @var string */
public const DOWN = 'down';
/** @var Application */ /** @var Application */
protected $app; protected $app;

@ -18,8 +18,11 @@ class Handler
/** @var Request */ /** @var Request */
protected $request; protected $request;
const ENV_PRODUCTION = 'prod'; /** @var string */
const ENV_DEVELOPMENT = 'dev'; public const ENV_PRODUCTION = 'prod';
/** @var string */
public const ENV_DEVELOPMENT = 'dev';
/** /**
* Handler constructor. * Handler constructor.

@ -13,7 +13,7 @@ class Legacy implements HandlerInterface
*/ */
public function render($request, Throwable $e) public function render($request, Throwable $e)
{ {
echo 'An <del>un</del>expected error occurred, a team of untrained monkeys has been dispatched to deal with it.'; echo 'An <del>un</del>expected error occurred. A team of untrained monkeys has been dispatched to fix it.';
} }
/** /**

@ -15,7 +15,11 @@ class LegacyDevelopment extends Legacy
{ {
$file = $this->stripBasePath($e->getFile()); $file = $this->stripBasePath($e->getFile());
echo '<pre style="background-color:#333;color:#ccc;z-index:1000;position:fixed;bottom:1em;padding:1em;width:97%;max-height: 90%;overflow-y:auto;">'; echo sprintf(
'<pre style="%s">',
'background-color:#333;color:#ccc;z-index:1000;position:fixed;'
. 'bottom:1em;padding:1em;width:97%;max-height:90%;overflow-y:auto;'
);
echo sprintf('%s: (%s)' . PHP_EOL, get_class($e), $e->getCode()); echo sprintf('%s: (%s)' . PHP_EOL, get_class($e), $e->getCode());
$data = [ $data = [
'string' => $e->getMessage(), 'string' => $e->getMessage(),

@ -17,10 +17,12 @@ trait ValidatesRequest
*/ */
protected function validate(Request $request, array $rules) protected function validate(Request $request, array $rules)
{ {
if (!$this->validator->validate( $isValid = $this->validator->validate(
(array)$request->getParsedBody(), (array)$request->getParsedBody(),
$rules $rules
)) { );
if (!$isValid) {
throw new ValidationException($this->validator); throw new ValidationException($this->validator);
} }

@ -82,7 +82,7 @@ class LegacyMiddleware implements MiddlewareInterface
$page = 404; $page = 404;
$title = $translator->translate('Page not found'); $title = $translator->translate('Page not found');
$content = $translator->translate('This page could not be found or you don\'t have permission to view it. You probably have to sign in or register in order to gain access!'); $content = $translator->translate('page.404.text');
} }
return $this->renderPage($page, $title, $content); return $this->renderPage($page, $title, $content);
@ -103,14 +103,17 @@ class LegacyMiddleware implements MiddlewareInterface
case 'ical': case 'ical':
require_once realpath(__DIR__ . '/../../includes/pages/user_ical.php'); require_once realpath(__DIR__ . '/../../includes/pages/user_ical.php');
user_ical(); user_ical();
break;
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case 'atom': case 'atom':
require_once realpath(__DIR__ . '/../../includes/pages/user_atom.php'); require_once realpath(__DIR__ . '/../../includes/pages/user_atom.php');
user_atom(); user_atom();
break;
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case 'shifts_json_export': case 'shifts_json_export':
require_once realpath(__DIR__ . '/../../includes/controller/shifts_controller.php'); require_once realpath(__DIR__ . '/../../includes/controller/shifts_controller.php');
shifts_json_export_controller(); shifts_json_export_controller();
break;
case 'public_dashboard': case 'public_dashboard':
return public_dashboard_controller(); return public_dashboard_controller();
case 'angeltypes': case 'angeltypes':

@ -24,7 +24,7 @@ class LogEntry extends BaseModel
public $timestamps = true; public $timestamps = true;
/** @var null Disable updated_at */ /** @var null Disable updated_at */
const UPDATED_AT = null; public const UPDATED_AT = null;
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.

@ -18,7 +18,7 @@ class PasswordReset extends HasUserModel
public $timestamps = true; public $timestamps = true;
/** @var null Disable updated_at */ /** @var null Disable updated_at */
const UPDATED_AT = null; public const UPDATED_AT = null;
/** The attributes that are mass assignable */ /** The attributes that are mass assignable */
protected $fillable = [ protected $fillable = [

@ -1,5 +1,4 @@
<?php <?php
// Some useful functions
use Engelsystem\Application; use Engelsystem\Application;
use Engelsystem\Config\Config; use Engelsystem\Config\Config;

@ -13,7 +13,8 @@ class LogEntryTest extends TestCase
*/ */
public function testFilter() public function testFilter()
{ {
foreach ([ foreach (
[
'Lorem Ipsum' => LogLevel::INFO, 'Lorem Ipsum' => LogLevel::INFO,
'Some test content' => LogLevel::ERROR, 'Some test content' => LogLevel::ERROR,
'Foo bar bartz!' => LogLevel::INFO, 'Foo bar bartz!' => LogLevel::INFO,
@ -21,7 +22,8 @@ class LogEntryTest extends TestCase
'This is a Test!' => LogLevel::INFO, 'This is a Test!' => LogLevel::INFO,
'I\'m verbose notice!' => LogLevel::DEBUG, 'I\'m verbose notice!' => LogLevel::DEBUG,
'The newest stuff!!' => LogLevel::ERROR, 'The newest stuff!!' => LogLevel::ERROR,
] as $message => $level) { ] as $message => $level
) {
$entry = new LogEntry(['level' => $level, 'message' => $message]); $entry = new LogEntry(['level' => $level, 'message' => $message]);
$entry->save(); $entry->save();
} }

@ -152,7 +152,7 @@ class PasswordResetControllerTest extends TestCase
$response = $controller->postResetPassword($request); $response = $controller->postResetPassword($request);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEmpty((new PasswordReset)->find($user->id)); $this->assertEmpty((new PasswordReset())->find($user->id));
$this->assertNotNull(auth()->authenticate($user->name, $password)); $this->assertNotNull(auth()->authenticate($user->name, $password));
} }

@ -259,7 +259,9 @@ class AuthenticatorTest extends ServiceProviderTest
return new class extends Authenticator return new class extends Authenticator
{ {
/** @noinspection PhpMissingParentConstructorInspection */ /** @noinspection PhpMissingParentConstructorInspection */
public function __construct() { } public function __construct()
{
}
}; };
} }
} }

@ -32,7 +32,7 @@ class TranslatorTest extends ServiceProviderTest
->method('__invoke') ->method('__invoke')
->withConsecutive(['te_ST'], ['fo_OO']); ->withConsecutive(['te_ST'], ['fo_OO']);
$translator = new Translator($locale, 'fo_OO', function () { }, $locales, $localeChange); $translator = new Translator($locale, 'fo_OO', [$this, 'doNothing'], $locales, $localeChange);
$this->assertEquals($locales, $translator->getLocales()); $this->assertEquals($locales, $translator->getLocales());
$this->assertEquals($locale, $translator->getLocale()); $this->assertEquals($locale, $translator->getLocale());
@ -55,7 +55,7 @@ class TranslatorTest extends ServiceProviderTest
{ {
/** @var Translator|MockObject $translator */ /** @var Translator|MockObject $translator */
$translator = $this->getMockBuilder(Translator::class) $translator = $this->getMockBuilder(Translator::class)
->setConstructorArgs(['de_DE', 'en_US', function () { }, ['de_DE' => 'Deutsch']]) ->setConstructorArgs(['de_DE', 'en_US', [$this, 'doNothing'], ['de_DE' => 'Deutsch']])
->onlyMethods(['translateText']) ->onlyMethods(['translateText'])
->getMock(); ->getMock();
$translator->expects($this->exactly(2)) $translator->expects($this->exactly(2))
@ -77,7 +77,7 @@ class TranslatorTest extends ServiceProviderTest
{ {
/** @var Translator|MockObject $translator */ /** @var Translator|MockObject $translator */
$translator = $this->getMockBuilder(Translator::class) $translator = $this->getMockBuilder(Translator::class)
->setConstructorArgs(['de_DE', 'en_US', function () { }, ['de_DE' => 'Deutsch']]) ->setConstructorArgs(['de_DE', 'en_US', [$this, 'doNothing'], ['de_DE' => 'Deutsch']])
->onlyMethods(['translateText']) ->onlyMethods(['translateText'])
->getMock(); ->getMock();
$translator->expects($this->once()) $translator->expects($this->once())
@ -131,4 +131,11 @@ class TranslatorTest extends ServiceProviderTest
// Successful translation // Successful translation
$this->assertEquals('Lorem test3!', $translator->translatePlural('foo.barf', 'foo.bar2', 3, ['test3'])); $this->assertEquals('Lorem test3!', $translator->translatePlural('foo.barf', 'foo.bar2', 3, ['test3']));
} }
/**
* Does nothing
*/
public function doNothing()
{
}
} }

@ -20,7 +20,7 @@ class Psr7ServiceProviderTest extends ServiceProviderTest
*/ */
public function testRegister() public function testRegister()
{ {
$app = new Application; $app = new Application();
$serviceProvider = new Psr7ServiceProvider($app); $serviceProvider = new Psr7ServiceProvider($app);
$serviceProvider->register(); $serviceProvider->register();

@ -69,7 +69,10 @@ class EngelsystemLoggerTest extends ServiceProviderTest
'user' => 'user' =>
new class new class
{ {
public function __toString() { return 'Bar'; } public function __toString()
{
return 'Bar';
}
} }
]); ]);
} }

@ -16,7 +16,8 @@ class LogEntryTest extends TestCase
*/ */
public function testFilter() public function testFilter()
{ {
foreach ([ foreach (
[
'I\'m an info' => LogLevel::INFO, 'I\'m an info' => LogLevel::INFO,
'*Insert explosion here*' => LogLevel::EMERGENCY, '*Insert explosion here*' => LogLevel::EMERGENCY,
'Tracing along' => LogLevel::DEBUG, 'Tracing along' => LogLevel::DEBUG,
@ -24,7 +25,8 @@ class LogEntryTest extends TestCase
'It\'s happening' => LogLevel::INFO, 'It\'s happening' => LogLevel::INFO,
'Something is wrong' => LogLevel::ERROR, 'Something is wrong' => LogLevel::ERROR,
'Ohi' => LogLevel::INFO, 'Ohi' => LogLevel::INFO,
] as $message => $level) { ] as $message => $level
) {
(new LogEntry(['level' => $level, 'message' => $message]))->save(); (new LogEntry(['level' => $level, 'message' => $message]))->save();
} }

@ -113,7 +113,7 @@ class UserTest extends TestCase
foreach ($modelData as $data) { foreach ($modelData as $data) {
/** @var BaseModel $model */ /** @var BaseModel $model */
$model = (new $class); $model = $this->app->make($class);
$stored = $model->create($data + ['user_id' => $user->id]); $stored = $model->create($data + ['user_id' => $user->id]);
$relatedModelIds[] = $stored->id; $relatedModelIds[] = $stored->id;
} }

Loading…
Cancel
Save