diff --git a/.github/workflows/lint-php-cs.yml b/.github/workflows/lint-php-cs.yml new file mode 100644 index 0000000..d4288fb --- /dev/null +++ b/.github/workflows/lint-php-cs.yml @@ -0,0 +1,40 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization + +name: Lint php-cs + +on: pull_request + +permissions: + contents: read + +concurrency: + group: lint-php-cs-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint: + runs-on: self-hosted + + name: php-cs + + steps: + - name: Checkout + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + + - name: Set up php + uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2 + with: + php-version: 8.1 + coverage: none + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: composer i + + - name: Lint + run: composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 ) \ No newline at end of file diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..35158d2 --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.3.2","version":"3.49.0","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces_position":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["property","method","const"]},"align_multiline_comment":true,"array_indentation":true,"array_syntax":true,"binary_operator_spaces":{"default":"single_space"},"blank_line_after_opening_tag":true,"curly_braces_position":{"classes_opening_brace":"same_line","functions_opening_brace":"same_line"},"list_syntax":true,"no_leading_import_slash":true,"no_spaces_inside_parenthesis":true,"no_unused_imports":true,"nullable_type_declaration_for_default_null_value":true,"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"alpha"},"yoda_style":{"equal":false,"identical":false,"less_and_greater":false}},"hashes":{"appinfo\/routes.php":"79bcdccfabfe54c0df0baea844b48ee4","lib\/Controller\/GroceryListController.php":"def791ca24cf5f2e34af55826b1ed464","lib\/Db\/Category.php":"a5c68adfa19c127fbc9feef6b88cf895","lib\/Db\/CategoryMapper.php":"1cd303433beeab312720ef81d189ad4c","lib\/Db\/GroceryList.php":"7bd681e52f1e8282bb973d53f59dc966","lib\/Db\/GroceryListMapper.php":"65ee2eb3d72a15259c82fc3077fa6610","lib\/Db\/Item.php":"4469d2df5dd2b05b9227ec96c4210537","lib\/Db\/Sharee.php":"7654847c2162f0a6b3b951d5073a5e60","lib\/Db\/ItemMapper.php":"66cd13910ba9337251ed0096c95dbb62","lib\/Db\/ShareeGroceryListMapper.php":"e162ee885f07ce040ee5e68aa075cd3f","lib\/Migration\/Version000000Date20200604211400.php":"e39f6e7eff9ed0bcecfc7cbb137e196c","templates\/main.php":"245a35b8c13e475da18807c6caaf6475"}} \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..42e6131 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,20 @@ +getFinder() + ->ignoreVCSIgnored(true) + ->notPath('build') + ->notPath('l10n') + ->notPath('src') + ->notPath('lib/Vendor') + ->notPath('vendor') + ->notPath('vendor-bin') + ->in(__DIR__); +return $config; \ No newline at end of file diff --git a/appinfo/routes.php b/appinfo/routes.php index dd62e88..71d03ac 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -1,4 +1,5 @@ [ ['name' => 'GroceryList#showGroceryList', 'url' => '/list/{id}', 'verb' => 'GET'], diff --git a/composer.json b/composer.json index d19fb77..57a1002 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,20 @@ { - "name": "tobiaskaminsky/grocery_list-0.1", - "description": "Grocery list for Nextcloud", - "type": "project", - "license": "AGPL", - "authors": [ - { - "name": "Tobias Kaminsky" - } - ], - "require": {}, - "require-dev": { + "name": "tobiaskaminsky/grocery_list-0.1", + "description": "Grocery list for Nextcloud", + "type": "project", + "license": "AGPL", + "authors": [ + { + "name": "Tobias Kaminsky" } + ], + "require": {}, + "require-dev": { + "nextcloud/coding-standard": "^1.1.1" + }, + "scripts": { + "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", + "cs:fix": "php-cs-fixer fix", + "cs:check": "php-cs-fixer fix --dry-run --diff" + } } diff --git a/composer.lock b/composer.lock index 418f65f..dbe41e0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,103 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3c02450d2be4d3a885985ab0b7008b2a", + "content-hash": "b5445dbecdbb8dccfae7e65679bc8699", "packages": [], - "packages-dev": [], + "packages-dev": [ + { + "name": "nextcloud/coding-standard", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/nextcloud/coding-standard.git", + "reference": "cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e", + "reference": "cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0", + "php-cs-fixer/shim": "^3.17" + }, + "type": "library", + "autoload": { + "psr-4": { + "Nextcloud\\CodingStandard\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" + } + ], + "description": "Nextcloud coding standards for the php cs fixer", + "support": { + "issues": "https://github.com/nextcloud/coding-standard/issues", + "source": "https://github.com/nextcloud/coding-standard/tree/v1.2.1" + }, + "time": "2024-02-01T14:54:37+00:00" + }, + { + "name": "php-cs-fixer/shim", + "version": "v3.49.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/shim.git", + "reference": "f7d3219cac46632f12362c9aa7c2ac0d2fe92c52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/f7d3219cac46632f12362c9aa7c2ac0d2fe92c52", + "reference": "f7d3219cac46632f12362c9aa7c2ac0d2fe92c52", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0" + }, + "replace": { + "friendsofphp/php-cs-fixer": "self.version" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer", + "php-cs-fixer.phar" + ], + "type": "application", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz RumiƄski", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "support": { + "issues": "https://github.com/PHP-CS-Fixer/shim/issues", + "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.49.0" + }, + "time": "2024-02-02T00:42:09+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/lib/Controller/GroceryListController.php b/lib/Controller/GroceryListController.php index b445f9e..633ad0d 100644 --- a/lib/Controller/GroceryListController.php +++ b/lib/Controller/GroceryListController.php @@ -9,14 +9,13 @@ use OCA\GroceryList\Db\Item; use OCA\GroceryList\Db\ItemMapper; use OCA\GroceryList\Db\ShareeGroceryListMapper; -use OCP\ILogger; -use OCP\IRequest; -use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\ILogger; +use OCP\IRequest; -class GroceryListController extends Controller -{ +class GroceryListController extends Controller { private GroceryListMapper $groceryListMapper; private ItemMapper $itemMapper; @@ -26,14 +25,13 @@ class GroceryListController extends Controller private ILogger $logger; public function __construct($AppName, - IRequest $request, - GroceryListMapper $groceryListMapper, - ItemMapper $itemMapper, - CategoryMapper $categoryMapper, - ShareeGroceryListMapper $shareeMapper, - ILogger $logger, - $UserId) - { + IRequest $request, + GroceryListMapper $groceryListMapper, + ItemMapper $itemMapper, + CategoryMapper $categoryMapper, + ShareeGroceryListMapper $shareeMapper, + ILogger $logger, + $UserId) { parent::__construct($AppName, $request); $this->groceryListMapper = $groceryListMapper; $this->itemMapper = $itemMapper; @@ -47,8 +45,7 @@ public function __construct($AppName, * @NoAdminRequired * @NoCSRFRequired */ - public function index() - { + public function index() { // Register all scripts and styles we use on the frontend \OCP\Util::addScript($this->appName, $this->appName . '-main'); // adding `js/grocerylist-main.mjs` generated from JS source \OCP\Util::addStyle($this->appName, $this->appName . '-main'); // adding `css/grocerylist-style.css` generated from JS source @@ -60,8 +57,7 @@ public function index() * @NoAdminRequired * @NoCSRFRequired */ - public function showGroceryList($id) - { + public function showGroceryList($id) { return $this->index(); } @@ -69,8 +65,7 @@ public function showGroceryList($id) * @NoAdminRequired * @NoCSRFRequired */ - public function showGroceryListSettings($id) - { + public function showGroceryListSettings($id) { return $this->index(); } @@ -93,8 +88,7 @@ public function lists() * @param string $title * @return DataResponse */ - public function saveList(string $title) - { + public function saveList(string $title) { $groceryList = new GroceryList(); $groceryList->setTitle($title); $groceryList->setUserId($this->userId); @@ -107,8 +101,7 @@ public function saveList(string $title) * @param int $id * @return \OCP\AppFramework\Db\Entity */ - public function deleteList(int $id) - { + public function deleteList(int $id) { $groceryList = $this->groceryListMapper->find($id); $this->groceryListMapper->delete($groceryList); @@ -121,8 +114,7 @@ public function deleteList(int $id) * @param string $title * @param string $showOnlyUnchecked */ - public function renameList(int $id, string $title) - { + public function renameList(int $id, string $title) { $list = $this->groceryListMapper->find($id); $list->setTitle($title); @@ -136,8 +128,7 @@ public function renameList(int $id, string $title) * @param string $title * @param string $showOnlyUnchecked */ - public function updateList(int $id, string $title, int $showOnlyUnchecked = 0) - { + public function updateList(int $id, string $title, int $showOnlyUnchecked = 0) { $list = $this->groceryListMapper->find($id); $list->setShowOnlyUnchecked($showOnlyUnchecked); $list->setTitle($title); @@ -151,8 +142,7 @@ public function updateList(int $id, string $title, int $showOnlyUnchecked = 0) * @param string $title * @param string $showOnlyUnchecked */ - public function updateListVisibility(int $id, int $showOnlyUnchecked = 0) - { + public function updateListVisibility(int $id, int $showOnlyUnchecked = 0) { $list = $this->groceryListMapper->find($id); $list->setShowOnlyUnchecked($showOnlyUnchecked); @@ -164,8 +154,7 @@ public function updateListVisibility(int $id, int $showOnlyUnchecked = 0) * @NoCSRFRequired * @return DataResponse */ - public function showList(int $id) - { + public function showList(int $id) { return new DataResponse($this->groceryListMapper->find($id)); } @@ -174,8 +163,7 @@ public function showList(int $id) * @NoCSRFRequired * @param int $id */ - public function listItems(int $id) - { + public function listItems(int $id) { return new DataResponse($this->itemMapper->findAll($id)); } @@ -202,8 +190,7 @@ public function deleteItem(int $id) { * @NoAdminRequired * @param int $id */ - public function listCategories(int $id) - { + public function listCategories(int $id) { $returnList = []; $categories = $this->categoryMapper->findAll($id); @@ -220,8 +207,7 @@ public function listCategories(int $id) * @NoAdminRequired * @param int $id */ - public function listAllCategories(int $id) - { + public function listAllCategories(int $id) { return new DataResponse($this->categoryMapper->findAll($id)); } @@ -233,8 +219,7 @@ public function listAllCategories(int $id) * @param int $list * @return DataResponse */ - public function addItem(string $name, string $quantity, int $category, int $list) - { + public function addItem(string $name, string $quantity, int $category, int $list) { $item = new Item(); $item->setName($name); $item->setQuantity($quantity); @@ -252,8 +237,7 @@ public function addItem(string $name, string $quantity, int $category, int $list * @param int $category * @return DataResponse */ - public function updateItem(int $id, string $name, string $quantity, int $category) - { + public function updateItem(int $id, string $name, string $quantity, int $category) { $item = $this->itemMapper->find($id); $item->setName($name); $item->setQuantity($quantity); @@ -265,8 +249,7 @@ public function updateItem(int $id, string $name, string $quantity, int $categor /** * @NoAdminRequired */ - public function hideItem(int $id) - { + public function hideItem(int $id) { $item = $this->itemMapper->find($id); $item->setHidden(time()); @@ -279,8 +262,7 @@ public function hideItem(int $id) * @param bool $checked * @return DataResponse */ - public function checkItem(int $id, bool $checked) - { + public function checkItem(int $id, bool $checked) { $item = $this->itemMapper->find($id); $item->setChecked($checked); @@ -293,8 +275,7 @@ public function checkItem(int $id, bool $checked) * @param string $name * @return DataResponse */ - public function addCategory(int $id, string $name) - { + public function addCategory(int $id, string $name) { $category = new Category(); $category->setList($id); $category->setName($name); @@ -311,8 +292,7 @@ public function addCategory(int $id, string $name) * @param string $newName * @return DataResponse */ - public function updateCategory(int $id, string $newName) - { + public function updateCategory(int $id, string $newName) { $category = $this->categoryMapper->find($id); $category->setName($newName); @@ -325,8 +305,7 @@ public function updateCategory(int $id, string $newName) * @NoAdminRequired * @param int $id */ - public function sharees(int $id): DataResponse - { + public function sharees(int $id): DataResponse { return new DataResponse($this->shareeMapper->findSharees($id)); } } diff --git a/lib/Db/CategoryMapper.php b/lib/Db/CategoryMapper.php index 446d8cb..ad6563f 100644 --- a/lib/Db/CategoryMapper.php +++ b/lib/Db/CategoryMapper.php @@ -2,9 +2,8 @@ namespace OCA\GroceryList\Db; -use OCP\AppFramework\Db\Entity; -use OCP\IDBConnection; use OCP\AppFramework\Db\QBMapper; +use OCP\IDBConnection; /** * @template-implements QBMapper diff --git a/lib/Db/GroceryListMapper.php b/lib/Db/GroceryListMapper.php index 7d535e5..cd96850 100644 --- a/lib/Db/GroceryListMapper.php +++ b/lib/Db/GroceryListMapper.php @@ -2,9 +2,8 @@ namespace OCA\GroceryList\Db; -use OCP\AppFramework\Db\Entity; -use OCP\IDBConnection; use OCP\AppFramework\Db\QBMapper; +use OCP\IDBConnection; /** * @template-implements QBMapper @@ -34,7 +33,7 @@ public function find(int $id) : GroceryList { return $result[0]; } else { $sharedList = $this->shareeMapper->find($id); - return $this->findById($sharedList->list); + return $this->findById($sharedList->list); } } diff --git a/lib/Db/ItemMapper.php b/lib/Db/ItemMapper.php index 235c7c8..b05cdc2 100644 --- a/lib/Db/ItemMapper.php +++ b/lib/Db/ItemMapper.php @@ -2,17 +2,16 @@ namespace OCA\GroceryList\Db; -use OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\QBMapper; use OCP\DB\Exception; use OCP\IDBConnection; -use OCP\AppFramework\Db\QBMapper; /** * @template-implements QBMapper */ class ItemMapper extends QBMapper { - const OFFSET = 15 * 60; + public const OFFSET = 15 * 60; public function __construct(IDBConnection $db) { parent::__construct($db, 'grocerylist_items', Item::class); diff --git a/lib/Db/ShareeGroceryListMapper.php b/lib/Db/ShareeGroceryListMapper.php index c31e567..2201b73 100644 --- a/lib/Db/ShareeGroceryListMapper.php +++ b/lib/Db/ShareeGroceryListMapper.php @@ -2,9 +2,9 @@ namespace OCA\GroceryList\Db; +use OCP\AppFramework\Db\QBMapper; use OCP\DB\Exception; use OCP\IDBConnection; -use OCP\AppFramework\Db\QBMapper; /** * @template-implements QBMapper diff --git a/lib/Migration/Version000000Date20200604211400.php b/lib/Migration/Version000000Date20200604211400.php index 8b497c2..a95351a 100644 --- a/lib/Migration/Version000000Date20200604211400.php +++ b/lib/Migration/Version000000Date20200604211400.php @@ -4,8 +4,8 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\Migration\SimpleMigrationStep; use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; class Version000000Date20200604211400 extends SimpleMigrationStep {