Formatting to follow PSR-12

This commit is contained in:
Igor Scheller 2019-11-10 23:26:23 +01:00
parent b878740f80
commit 68afc74b03
28 changed files with 127 additions and 65 deletions

View File

@ -70,13 +70,24 @@ test:
- 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
- cp -R tests/ phpunit.xml "${DOCROOT}"
- HOMEDIR=$(pwd)
- HOMEDIR=$PWD
- cd "${DOCROOT}"
- composer --no-ansi install
- ./bin/migrate
script:
- vendor/bin/phpunit -v --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
- bin/migrate down
- ./vendor/bin/phpunit -v --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
- ./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:
<<: *docker_definition

View File

@ -196,5 +196,9 @@ For more information on how to use it call `./bin/migrate help`
### 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
### Codestyle
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/).
### Code style
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/
```

View File

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

View File

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

View File

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

View File

@ -83,8 +83,10 @@ class CreateUsersTables extends Migration
});
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 */
$users = $this->schema->getConnection()->table('User')->get();
foreach ($users as $data) {
$user = new User([
'name' => $data->Nick,
@ -94,10 +96,7 @@ class CreateUsersTables extends Migration
'last_login_at' => Carbon::createFromTimestamp($data->lastLogIn),
]);
$user->setAttribute('id', $data->UID);
if (!in_array(
$data->CreateDate,
['0000-00-00 00:00:00', '0001-01-01 00:00:00', '1000-01-01 00:00:00']
)) {
if (!in_array($data->CreateDate, $emptyDates)) {
$user->setAttribute('created_at', new Carbon($data->CreateDate));
}
$user->save();
@ -114,8 +113,12 @@ class CreateUsersTables extends Migration
'first_name' => $data->Vorname ?: null,
'last_name' => $data->Name ?: null,
'shirt_size' => $data->Size ?: null,
'planned_arrival_date' => $data->planned_arrival_date ? Carbon::createFromTimestamp($data->planned_arrival_date) : null,
'planned_departure_date' => $data->planned_departure_date ? Carbon::createFromTimestamp($data->planned_departure_date) : null,
'planned_arrival_date' => $data->planned_arrival_date
? Carbon::createFromTimestamp($data->planned_arrival_date)
: null,
'planned_departure_date' => $data->planned_departure_date
? Carbon::createFromTimestamp($data->planned_departure_date)
: null,
]);
$personalData->user()
->associate($user)
@ -181,7 +184,7 @@ class CreateUsersTables extends Migration
$table->string('DECT', 5)->nullable();
$table->string('Handy', 40)->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('Size', 4)->nullable();
$table->string('Passwort', 128)->nullable();
@ -244,8 +247,12 @@ class CreateUsersTables extends Migration
'api_key' => $user->api_key,
'got_voucher' => $state->got_voucher,
'arrival_date' => $state->arrival_date ? $state->arrival_date->getTimestamp() : null,
'planned_arrival_date' => $personal->planned_arrival_date ? $personal->planned_arrival_date->getTimestamp() : null,
'planned_departure_date' => $personal->planned_departure_date ? $personal->planned_departure_date->getTimestamp() : null,
'planned_arrival_date' => $personal->planned_arrival_date
? $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,
]);
}

View File

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

View File

@ -2754,9 +2754,7 @@ msgid "Development Platform"
msgstr "Entwicklerplattform"
#: src/Middleware/LegacyMiddleware.php
msgid ""
"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 "page.404.text"
msgstr ""
"Diese Seite existiert nicht oder Du hast keinen Zugriff. Melde Dich an um "
"Zugriff zu erhalten!"

View File

@ -25,6 +25,11 @@ msgstr ""
msgid "form.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"
msgstr ""
"The original engelsystem was written by "

View File

@ -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 mixed $value
*/
public function share($key, $value = null) { }
public function share($key, $value = null)
{
}
}

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ class Legacy implements HandlerInterface
*/
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.';
}
/**

View File

@ -15,7 +15,11 @@ class LegacyDevelopment extends Legacy
{
$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());
$data = [
'string' => $e->getMessage(),

View File

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

View File

@ -82,7 +82,7 @@ class LegacyMiddleware implements MiddlewareInterface
$page = 404;
$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);
@ -103,14 +103,17 @@ class LegacyMiddleware implements MiddlewareInterface
case 'ical':
require_once realpath(__DIR__ . '/../../includes/pages/user_ical.php');
user_ical();
break;
/** @noinspection PhpMissingBreakStatementInspection */
case 'atom':
require_once realpath(__DIR__ . '/../../includes/pages/user_atom.php');
user_atom();
break;
/** @noinspection PhpMissingBreakStatementInspection */
case 'shifts_json_export':
require_once realpath(__DIR__ . '/../../includes/controller/shifts_controller.php');
shifts_json_export_controller();
break;
case 'public_dashboard':
return public_dashboard_controller();
case 'angeltypes':

View File

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

View File

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

View File

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

View File

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

View File

@ -152,7 +152,7 @@ class PasswordResetControllerTest extends TestCase
$response = $controller->postResetPassword($request);
$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));
}

View File

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

View File

@ -32,7 +32,7 @@ class TranslatorTest extends ServiceProviderTest
->method('__invoke')
->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($locale, $translator->getLocale());
@ -55,7 +55,7 @@ class TranslatorTest extends ServiceProviderTest
{
/** @var Translator|MockObject $translator */
$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'])
->getMock();
$translator->expects($this->exactly(2))
@ -77,7 +77,7 @@ class TranslatorTest extends ServiceProviderTest
{
/** @var Translator|MockObject $translator */
$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'])
->getMock();
$translator->expects($this->once())
@ -131,4 +131,11 @@ class TranslatorTest extends ServiceProviderTest
// Successful translation
$this->assertEquals('Lorem test3!', $translator->translatePlural('foo.barf', 'foo.bar2', 3, ['test3']));
}
/**
* Does nothing
*/
public function doNothing()
{
}
}

View File

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

View File

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

View File

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

View File

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