Upgraded to PHP-CS-Fixer v3

This commit is contained in:
Bernd Bestel 2021-07-03 17:46:47 +02:00
parent 766eae5a7a
commit 0f88eed08c
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
21 changed files with 267 additions and 211 deletions

95
.php-cs-fixer.php Normal file
View File

@ -0,0 +1,95 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude(['vendor'])
->ignoreVCSIgnored(true)
->files()->name('*.php')
->in(__DIR__)
;
$cfg = new PhpCsFixer\Config();
return $cfg
->setRules([
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'class_attributes_separation' => true,
'multiline_whitespace_before_semicolons' => false,
'single_quote' => true,
// 'blank_line_after_opening_tag' => true,
// 'blank_line_before_return' => true,
'braces' => [
'allow_single_line_closure' => true,
'position_after_anonymous_constructs' => 'same',
'position_after_control_structures' => 'next',
'position_after_functions_and_oop_constructs' => 'next',
],
// 'cast_spaces' => true,
// 'class_definition' => array('singleLine' => true),
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => true,
'function_typehint_space' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'include' => true,
'lowercase_cast' => true,
// 'native_function_casing' => true,
// 'new_with_braces' => true,
// 'no_blank_lines_after_class_opening' => true,
// 'no_blank_lines_after_phpdoc' => true,
// 'no_empty_comment' => true,
// 'no_empty_phpdoc' => true,
// 'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
// 'no_mixed_echo_print' => array('use' => 'echo'),
'no_multiline_whitespace_around_double_arrow' => true,
// 'no_short_bool_cast' => true,
// 'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
// 'no_trailing_comma_in_list_call' => true,
// 'no_trailing_comma_in_singleline_array' => true,
// 'no_unneeded_control_parentheses' => true,
// 'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
// 'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
// 'php_unit_fqcn_annotation' => true,
// 'phpdoc_align' => true,
// 'phpdoc_annotation_without_dot' => true,
// 'phpdoc_indent' => true,
// 'phpdoc_inline_tag' => true,
// 'phpdoc_no_access' => true,
// 'phpdoc_no_alias_tag' => true,
// 'phpdoc_no_empty_return' => true,
// 'phpdoc_no_package' => true,
// 'phpdoc_no_useless_inheritdoc' => true,
// 'phpdoc_return_self_reference' => true,
// 'phpdoc_scalar' => true,
// 'phpdoc_separation' => true,
// 'phpdoc_single_line_var_spacing' => true,
// 'phpdoc_summary' => true,
// 'phpdoc_to_comment' => true,
// 'phpdoc_trim' => true,
// 'phpdoc_types' => true,
// 'phpdoc_var_without_name' => true,
// 'pre_increment' => true,
// 'return_type_declaration' => true,
// 'self_accessor' => true,
// 'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
// 'single_class_element_per_statement' => true,
// 'space_after_semicolon' => true,
// 'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
// 'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
])
->setIndent("\t")
->setLineEnding("\n")
->setUsingCache(false)
->setFinder($finder)
;

97
.php_cs
View File

@ -1,97 +0,0 @@
<?php
return PhpCsFixer\Config::create()
->setRules(array(
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => array('syntax' => 'short'),
'combine_consecutive_unsets' => true,
'method_separation' => true,
'no_multiline_whitespace_before_semicolons' => true,
'single_quote' => true,
'binary_operator_spaces' => array(
'align_double_arrow' => false,
'align_equals' => false,
),
// 'blank_line_after_opening_tag' => true,
// 'blank_line_before_return' => true,
'braces' => array(
'allow_single_line_closure' => true,
'position_after_anonymous_constructs' => 'same',
'position_after_control_structures' => 'next',
'position_after_functions_and_oop_constructs' => 'next',
),
// 'cast_spaces' => true,
// 'class_definition' => array('singleLine' => true),
'concat_space' => array('spacing' => 'one'),
'declare_equal_normalize' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'include' => true,
'lowercase_cast' => true,
// 'native_function_casing' => true,
// 'new_with_braces' => true,
// 'no_blank_lines_after_class_opening' => true,
// 'no_blank_lines_after_phpdoc' => true,
// 'no_empty_comment' => true,
// 'no_empty_phpdoc' => true,
// 'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => array(
'extra',
'parenthesis_brace_block',
'square_brace_block',
'throw',
'use',
),
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
// 'no_mixed_echo_print' => array('use' => 'echo'),
'no_multiline_whitespace_around_double_arrow' => true,
// 'no_short_bool_cast' => true,
// 'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
// 'no_trailing_comma_in_list_call' => true,
// 'no_trailing_comma_in_singleline_array' => true,
// 'no_unneeded_control_parentheses' => true,
// 'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
// 'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
// 'php_unit_fqcn_annotation' => true,
// 'phpdoc_align' => true,
// 'phpdoc_annotation_without_dot' => true,
// 'phpdoc_indent' => true,
// 'phpdoc_inline_tag' => true,
// 'phpdoc_no_access' => true,
// 'phpdoc_no_alias_tag' => true,
// 'phpdoc_no_empty_return' => true,
// 'phpdoc_no_package' => true,
// 'phpdoc_no_useless_inheritdoc' => true,
// 'phpdoc_return_self_reference' => true,
// 'phpdoc_scalar' => true,
// 'phpdoc_separation' => true,
// 'phpdoc_single_line_var_spacing' => true,
// 'phpdoc_summary' => true,
// 'phpdoc_to_comment' => true,
// 'phpdoc_trim' => true,
// 'phpdoc_types' => true,
// 'phpdoc_var_without_name' => true,
// 'pre_increment' => true,
// 'return_type_declaration' => true,
// 'self_accessor' => true,
// 'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
// 'single_class_element_per_statement' => true,
// 'space_after_semicolon' => true,
// 'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
// 'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
))
->setIndent("\t")
->setLineEnding("\n")
;

View File

@ -109,9 +109,9 @@ Setting('TPRINTER_IP', '127.0.0.1'); // IP of the network printer
Setting('TPRINTER_PORT', 9100); // Port of printer, eg. 9100
//Configuration below if you are using a USB or serial printer
Setting('TPRINTER_CONNECTOR', '/dev/usb/lp0'); // Location of printer. For USB on Linux this is often '/dev/usb/lp0',
// for serial printers it could be similar to '/dev/ttyS0'
// Make sure that the user that runs the webserver has permissions to write to the printer!
// On Linux add your webserver user to the LP group with usermod -a -G lp www-data
// for serial printers it could be similar to '/dev/ttyS0'
// Make sure that the user that runs the webserver has permissions to write to the printer!
// On Linux add your webserver user to the LP group with usermod -a -G lp www-data
// Default user settings

View File

@ -9,7 +9,9 @@ class BaseApiController extends BaseController
protected $OpenApiSpec = null;
const PATTERN_FIELD = '[A-Za-z_][A-Za-z0-9_]+';
const PATTERN_OPERATOR = '!?(=|~|<|>|(>=)|(<=)|(§))';
const PATTERN_VALUE = '[A-Za-z_0-9.$#^|]+';
public function __construct(\DI\Container $container)

View File

@ -11,7 +11,7 @@ class FilesApiController extends BaseApiController
{
try
{
if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
{
throw new \Exception('Invalid file group');
}
@ -39,7 +39,7 @@ class FilesApiController extends BaseApiController
{
try
{
if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
{
throw new \Exception('Invalid file group');
}
@ -69,7 +69,7 @@ class FilesApiController extends BaseApiController
{
try
{
if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
{
throw new \Exception('Invalid file group');
}
@ -100,7 +100,7 @@ class FilesApiController extends BaseApiController
{
try
{
if(!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
if (!in_array($args['group'], $this->getOpenApiSpec()->components->internalSchemas->FileGroups->enum))
{
throw new \Exception('Invalid file group');
}

View File

@ -7,9 +7,8 @@ use Grocy\Services\StockService;
class PrintApiController extends BaseApiController
{
public function PrintShoppingListThermal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) {
public function PrintShoppingListThermal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
User::checkPermission($request, User::PERMISSION_SHOPPINGLIST);
@ -17,13 +16,15 @@ class PrintApiController extends BaseApiController
$params = $request->getQueryParams();
$listId = 1;
if (isset($params['list'])) {
if (isset($params['list']))
{
$listId = $params['list'];
}
$printHeader = true;
if (isset($params['printHeader'])) {
$printHeader = ($params['printHeader'] === "true");
if (isset($params['printHeader']))
{
$printHeader = ($params['printHeader'] === 'true');
}
$items = $this->getStockService()->GetShoppinglistInPrintableStrings($listId);
return $this->ApiResponse($response, $this->getPrintService()->printShoppingList($printHeader, $items));

View File

@ -512,7 +512,6 @@ class StockController extends BaseController
]);
}
public function Stockentries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$usersService = $this->getUsersService();

View File

@ -10,13 +10,17 @@ class User
const PERMISSION_ADMIN = 'ADMIN';
const PERMISSION_BATTERIES = 'BATTERIES';
const PERMISSION_BATTERIES_TRACK_CHARGE_CYCLE = 'BATTERIES_TRACK_CHARGE_CYCLE';
const PERMISSION_BATTERIES_UNDO_CHARGE_CYCLE = 'BATTERIES_UNDO_CHARGE_CYCLE';
const PERMISSION_CALENDAR = 'CALENDAR';
const PERMISSION_CHORES = 'CHORES';
const PERMISSION_CHORE_TRACK_EXECUTION = 'CHORE_TRACK_EXECUTION';
const PERMISSION_CHORE_UNDO_EXECUTION = 'CHORE_UNDO_EXECUTION';
const PERMISSION_EQUIPMENT = 'EQUIPMENT';
@ -24,28 +28,43 @@ class User
const PERMISSION_MASTER_DATA_EDIT = 'MASTER_DATA_EDIT';
const PERMISSION_RECIPES = 'RECIPES';
const PERMISSION_RECIPES_MEALPLAN = 'RECIPES_MEALPLAN';
const PERMISSION_SHOPPINGLIST = 'SHOPPINGLIST';
const PERMISSION_SHOPPINGLIST_ITEMS_ADD = 'SHOPPINGLIST_ITEMS_ADD';
const PERMISSION_SHOPPINGLIST_ITEMS_DELETE = 'SHOPPINGLIST_ITEMS_DELETE';
const PERMISSION_STOCK = 'STOCK';
const PERMISSION_STOCK_CONSUME = 'STOCK_CONSUME';
const PERMISSION_STOCK_EDIT = 'STOCK_EDIT';
const PERMISSION_STOCK_INVENTORY = 'STOCK_INVENTORY';
const PERMISSION_STOCK_OPEN = 'STOCK_OPEN';
const PERMISSION_STOCK_PURCHASE = 'STOCK_PURCHASE';
const PERMISSION_STOCK_TRANSFER = 'STOCK_TRANSFER';
const PERMISSION_TASKS = 'TASKS';
const PERMISSION_TASKS_MARK_COMPLETED = 'TASKS_MARK_COMPLETED';
const PERMISSION_TASKS_UNDO_EXECUTION = 'TASKS_UNDO_EXECUTION';
const PERMISSION_USERS = 'USERS';
const PERMISSION_USERS_CREATE = 'USERS_CREATE';
const PERMISSION_USERS_EDIT = 'USERS_EDIT';
const PERMISSION_USERS_EDIT_SELF = 'USERS_EDIT_SELF';
const PERMISSION_USERS_READ = 'USERS_READ';
/**

View File

@ -18,7 +18,9 @@ namespace Grocy\Helpers;
class Grocycode
{
public const PRODUCT = 'p';
public const BATTERY = 'b';
public const CHORE = 'c';
public const MAGIC = 'grcy';
@ -29,7 +31,9 @@ class Grocycode
public static $Items = [self::PRODUCT, self::BATTERY, self::CHORE];
private $type;
private $id;
private $extra_data = [];
/**

View File

@ -7,18 +7,18 @@ $db = $this->getDatabaseService()->GetDbConnection();
if (defined('GROCY_HTTP_USER'))
{
// Migrate old user defined in config file to database
$newUserRow = $db->users()->createRow(array(
$newUserRow = $db->users()->createRow([
'username' => GROCY_HTTP_USER,
'password' => password_hash(GROCY_HTTP_PASSWORD, PASSWORD_DEFAULT)
));
]);
$newUserRow->save();
}
else
{
// Create default user "admin" with password "admin"
$newUserRow = $db->users()->createRow(array(
$newUserRow = $db->users()->createRow([
'username' => 'admin',
'password' => password_hash('admin', PASSWORD_DEFAULT)
));
]);
$newUserRow->save();
}

View File

@ -2,7 +2,8 @@
// This is executed inside DatabaseMigrationService class/context
use \Grocy\Services\LocalizationService;
use Grocy\Services\LocalizationService;
$localizationService = $this->getLocalizationService();
$db = $this->getDatabaseService()->GetDbConnection();
@ -10,23 +11,23 @@ $db = $this->getDatabaseService()->GetDbConnection();
if ($db->quantity_units()->count() === 0)
{
// Create 2 default quantity units
$newRow = $db->quantity_units()->createRow(array(
$newRow = $db->quantity_units()->createRow([
'name' => $localizationService->__n(1, 'Piece', 'Pieces'),
'name_plural' => $localizationService->__n(2, 'Piece', 'Pieces')
));
]);
$newRow->save();
$newRow = $db->quantity_units()->createRow(array(
$newRow = $db->quantity_units()->createRow([
'name' => $localizationService->__n(1, 'Pack', 'Packs'),
'name_plural' => $localizationService->__n(2, 'Pack', 'Packs')
));
]);
$newRow->save();
}
if ($db->locations()->count() === 0)
{
// Create a default location
$newRow = $db->locations()->createRow(array(
$newRow = $db->locations()->createRow([
'name' => $localizationService->__t('Fridge')
));
]);
$newRow->save();
}

View File

@ -2,12 +2,13 @@
// This is executed inside DatabaseMigrationService class/context
use \Grocy\Services\LocalizationService;
use Grocy\Services\LocalizationService;
$localizationService = $this->getLocalizationService();
$db = $this->getDatabaseService()->GetDbConnection();
$defaultShoppingList = $db->shopping_lists()->where('id = 1')->fetch();
$defaultShoppingList->update(array(
$defaultShoppingList->update([
'name' => $localizationService->__t('Shopping list')
));
]);

View File

@ -71,5 +71,4 @@ class BaseService
{
return PrintService::getInstance();
}
}

View File

@ -5,15 +5,23 @@ namespace Grocy\Services;
class ChoresService extends BaseService
{
const CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER = 'in-alphabetical-order';
const CHORE_ASSIGNMENT_TYPE_NO_ASSIGNMENT = 'no-assignment';
const CHORE_ASSIGNMENT_TYPE_RANDOM = 'random';
const CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST = 'who-least-did-first';
const CHORE_PERIOD_TYPE_DAILY = 'daily';
const CHORE_PERIOD_TYPE_DYNAMIC_REGULAR = 'dynamic-regular';
const CHORE_PERIOD_TYPE_MANUALLY = 'manually';
const CHORE_PERIOD_TYPE_MONTHLY = 'monthly';
const CHORE_PERIOD_TYPE_WEEKLY = 'weekly';
const CHORE_PERIOD_TYPE_YEARLY = 'yearly';
public function CalculateNextExecutionAssignment($choreId)

View File

@ -5,7 +5,9 @@ namespace Grocy\Services;
class DatabaseService
{
private static $DbConnection = null;
private static $DbConnectionRaw = null;
private static $instance = null;
/**

View File

@ -58,12 +58,12 @@ class FilesService extends BaseService
$fileNameWithoutExtension = pathinfo($filePath, PATHINFO_FILENAME);
$fileExtension = pathinfo($filePath, PATHINFO_EXTENSION);
if (getimagesize($filePath) !== false) // Then the file is an image
{
if (getimagesize($filePath) !== false)
{ // Then the file is an image
// Also delete all corresponding "__downscaledto" files when deleting an image
$groupFolderPath = $this->StoragePath . '/' . $group;
$files = scandir($groupFolderPath);
foreach($files as $file)
foreach ($files as $file)
{
if (string_starts_with($file, $fileNameWithoutExtension . '__downscaledto'))
{

View File

@ -10,8 +10,6 @@ use Mike42\Escpos\Printer;
class PrintService extends BaseService
{
/**
* Initialises the printer
* @return Printer Printer handle
@ -19,15 +17,17 @@ class PrintService extends BaseService
*/
private static function getPrinterHandle()
{
if (GROCY_TPRINTER_IS_NETWORK_PRINTER) {
if (GROCY_TPRINTER_IS_NETWORK_PRINTER)
{
$connector = new NetworkPrintConnector(GROCY_TPRINTER_IP, GROCY_TPRINTER_PORT);
} else {
}
else
{
$connector = new FilePrintConnector(GROCY_TPRINTER_CONNECTOR);
}
return new Printer($connector);
}
/**
* Prints the grocy logo and date
* @param Printer $printer Printer handle
@ -41,7 +41,7 @@ class PrintService extends BaseService
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
$printer->setTextSize(4, 4);
$printer->setReverseColors(true);
$printer->text("grocy");
$printer->text('grocy');
$printer->setJustification();
$printer->setTextSize(1, 1);
$printer->setReverseColors(false);
@ -61,7 +61,9 @@ class PrintService extends BaseService
{
$printer = self::getPrinterHandle();
if ($printer === false)
throw new Exception("Unable to connect to printer");
{
throw new Exception('Unable to connect to printer');
}
if ($printHeader)
{
@ -78,7 +80,7 @@ class PrintService extends BaseService
$printer->cut();
$printer->close();
return [
'result' => "OK"
'result' => 'OK'
];
}
}

View File

@ -8,13 +8,21 @@ use Grocy\Helpers\WebhookRunner;
class StockService extends BaseService
{
const TRANSACTION_TYPE_CONSUME = 'consume';
const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction';
const TRANSACTION_TYPE_PRODUCT_OPENED = 'product-opened';
const TRANSACTION_TYPE_PURCHASE = 'purchase';
const TRANSACTION_TYPE_SELF_PRODUCTION = 'self-production';
const TRANSACTION_TYPE_STOCK_EDIT_NEW = 'stock-edit-new';
const TRANSACTION_TYPE_STOCK_EDIT_OLD = 'stock-edit-old';
const TRANSACTION_TYPE_TRANSFER_FROM = 'transfer_from';
const TRANSACTION_TYPE_TRANSFER_TO = 'transfer_to';
public function AddMissingProductsToShoppingList($listId = 1)

View File

@ -5,17 +5,29 @@ namespace Grocy\Services;
class UserfieldsService extends BaseService
{
const USERFIELD_TYPE_CHECKBOX = 'checkbox';
const USERFIELD_TYPE_DATE = 'date';
const USERFIELD_TYPE_DATETIME = 'datetime';
const USERFIELD_TYPE_DECIMAL_NUMBER = 'number-decimal';
const USERFIELD_TYPE_FILE = 'file';
const USERFIELD_TYPE_IMAGE = 'image';
const USERFIELD_TYPE_INTEGRAL_NUMBER = 'number-integral';
const USERFIELD_TYPE_LINK = 'link';
const USERFIELD_TYPE_LINK_WITH_TITLE = 'link-with-title';
const USERFIELD_TYPE_PRESET_CHECKLIST = 'preset-checklist';
const USERFIELD_TYPE_PRESET_LIST = 'preset-list';
const USERFIELD_TYPE_SINGLE_LINE_TEXT = 'text-single-line';
const USERFIELD_TYPE_SINGLE_MULTILINE_TEXT = 'text-multi-line';
protected $OpenApiSpec = null;