From d6108ca3bf9cf072bc5bce9eedb762ea262207b8 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 23 Nov 2019 15:20:10 +0000 Subject: [PATCH 001/118] #76 - Create composer.json --- .phalcon/.gitkeep | 0 composer.json | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) delete mode 100644 .phalcon/.gitkeep create mode 100644 composer.json diff --git a/.phalcon/.gitkeep b/.phalcon/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..2a7a6b2c --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "phalcon/invo", + "type": "library", + "description": "This is a sample application for the Phalcon PHP Framework", + "keywords": [ + "phalcon", + "framework", + "sample app", + "invo" + ], + "homepage": "https://phalcon.io", + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/phalcon/vokuro/graphs/contributors" + } + ], + "require": { + "php": ">=7.2", + "ext-phalcon": "~4.0.0-rc.3" + }, + "require-dev": { + "codeception/codeception": "^3.1", + "phalcon/ide-stubs": "4.0.0-rc.2" + }, + "autoload": { + "psr-4": { + "Invo\\": "app/" + } + }, + "archive": { + "exclude": [ + "CONTRIBUTING.md" + ] + } +} From fa326e5c87587f2f98ec8fb1f01d6b9eb534284d Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 23 Nov 2019 15:20:49 +0000 Subject: [PATCH 002/118] #76 - Refactor of views files --- app/views/about/index.volt | 6 ++- app/views/companies/edit.volt | 59 +++++++++++++---------------- app/views/companies/index.volt | 45 ++++++++++------------ app/views/companies/new.volt | 23 +++++------ app/views/companies/search.volt | 38 +++++++++---------- app/views/contact/index.volt | 1 - app/views/errors/show401.volt | 3 +- app/views/errors/show404.volt | 1 - app/views/errors/show500.volt | 3 +- app/views/index.volt | 31 +++++++-------- app/views/index/index.volt | 1 - app/views/invoices/index.volt | 1 - app/views/invoices/profile.volt | 3 +- app/views/layouts/companies.volt | 2 +- app/views/layouts/invoices.volt | 1 - app/views/layouts/products.volt | 1 - app/views/layouts/producttypes.volt | 1 - app/views/products/edit.volt | 1 - app/views/products/index.volt | 1 - app/views/products/new.volt | 1 - app/views/products/search.volt | 34 ++++++++--------- app/views/producttypes/edit.volt | 59 +++++++++++++---------------- app/views/producttypes/index.volt | 36 ++++++++---------- app/views/producttypes/new.volt | 32 ++++++++-------- app/views/producttypes/search.volt | 28 +++++++------- app/views/register/index.volt | 4 -- app/views/session/index.volt | 4 -- 27 files changed, 189 insertions(+), 231 deletions(-) diff --git a/app/views/about/index.volt b/app/views/about/index.volt index dcf3b09f..215de5ad 100644 --- a/app/views/about/index.volt +++ b/app/views/about/index.volt @@ -3,7 +3,9 @@

-This is a sample application for the Phalcon Framework. We expect to implement as many features as possible to show how the framework works and its potential. -Please write us if you have any feedback or comments. Feel free to clone the code of this application here. +This is a sample application for the Phalcon Framework. +We expect to implement as many features as possible to show how the framework works and its potential. +Please write us if you have any feedback or comments. +Feel free to clone the code of this application here. Thanks!

diff --git a/app/views/companies/edit.volt b/app/views/companies/edit.volt index 788c9dcc..97a87587 100644 --- a/app/views/companies/edit.volt +++ b/app/views/companies/edit.volt @@ -1,34 +1,29 @@ - {{ form("companies/save", 'role': 'form') }} - - - -{{ content() }} - -

Edit companies

- -
- -{% for element in form %} - {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} -{{ element }} - {% else %} -
- {{ element.label(['class': 'control-label']) }} -
- {{ element }} -
-
- {% endif %} -{% endfor %} - -
- + + + {{ content() }} + +

Edit companies

+ +
+ {% for element in form %} + {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} + {{ element }} + {% else %} +
+ {{ element.label(['class': 'control-label']) }} +
+ {{ element }} +
+
+ {% endif %} + {% endfor %} +
diff --git a/app/views/companies/index.volt b/app/views/companies/index.volt index 281a69b2..5c9633d7 100644 --- a/app/views/companies/index.volt +++ b/app/views/companies/index.volt @@ -1,4 +1,3 @@ - {{ content() }}
@@ -6,28 +5,24 @@
{{ form("companies/search") }} - -

Search companies

- -
- -{% for element in form %} - {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} -{{ element }} - {% else %} -
- {{ element.label(['class': 'control-label']) }} -
- {{ element }} -
-
- {% endif %} -{% endfor %} - -
- {{ submit_button("Search", "class": "btn btn-primary") }} -
- -
- +

Search companies

+ +
+ {% for element in form %} + {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} + {{ element }} + {% else %} +
+ {{ element.label(['class': 'control-label']) }} +
+ {{ element }} +
+
+ {% endif %} + {% endfor %} + +
+ {{ submit_button("Search", "class": "btn btn-primary") }} +
+
diff --git a/app/views/companies/new.volt b/app/views/companies/new.volt index 30377282..dc5d3305 100644 --- a/app/views/companies/new.volt +++ b/app/views/companies/new.volt @@ -1,8 +1,6 @@ - {{ content() }} {{ form("companies/create") }} - {% for company in page.items %} -{% if loop.first %} - - + {% if loop.first %} +
+ @@ -20,21 +20,21 @@ - -{% endif %} + + {% endif %} - - - - - - - - - + + + + + + + + + -{% if loop.last %} - + {% if loop.last %} + - -
Id NameAddress City
{{ company.id }}{{ company.name }}{{ company.telephone }}{{ company.address }}{{ company.city }}{{ link_to("companies/edit/" ~ company.id, ' Edit', "class": "btn btn-default") }}{{ link_to("companies/delete/" ~ company.id, ' Delete', "class": "btn btn-default") }}
{{ company.id }}{{ company.name }}{{ company.telephone }}{{ company.address }}{{ company.city }}{{ link_to("companies/edit/" ~ company.id, ' Edit', "class": "btn btn-default") }}{{ link_to("companies/delete/" ~ company.id, ' Delete', "class": "btn btn-default") }}
@@ -46,9 +46,9 @@
-{% endif %} + + + {% endif %} {% else %} No companies are recorded {% endfor %} diff --git a/app/views/contact/index.volt b/app/views/contact/index.volt index c2b06021..e023553f 100644 --- a/app/views/contact/index.volt +++ b/app/views/contact/index.volt @@ -1,4 +1,3 @@ - {{ content() }} diff --git a/app/views/errors/show404.volt b/app/views/errors/show404.volt index aa2410d1..091d9e29 100644 --- a/app/views/errors/show404.volt +++ b/app/views/errors/show404.volt @@ -1,4 +1,3 @@ - {{ content() }}
diff --git a/app/views/errors/show500.volt b/app/views/errors/show500.volt index aea18d09..336ee7fb 100644 --- a/app/views/errors/show500.volt +++ b/app/views/errors/show500.volt @@ -1,8 +1,7 @@ - {{ content() }}

Internal Error

Something went wrong, if the error continue please contact us

{{ link_to('index', 'Home', 'class': 'btn btn-primary') }}

-
\ No newline at end of file +
diff --git a/app/views/index.volt b/app/views/index.volt index 1cf455f1..5b5097a2 100644 --- a/app/views/index.volt +++ b/app/views/index.volt @@ -1,17 +1,18 @@ - - - - {{ get_title() }} - {{ stylesheet_link('css/bootstrap.min.css') }} - - - - - - {{ content() }} - {{ javascript_include('js/jquery.min.js') }} - {{ javascript_include('js/bootstrap.min.js') }} - {{ javascript_include('js/utils.js') }} - + + + Phalcon Invo + + {{ get_title() }} + {{ stylesheet_link('css/bootstrap.min.css') }} + + + + + +{{ content() }} +{{ javascript_include('js/jquery.min.js') }} +{{ javascript_include('js/bootstrap.min.js') }} +{{ javascript_include('js/utils.js') }} + diff --git a/app/views/index/index.volt b/app/views/index/index.volt index 0fdd2f6b..c29ecb13 100644 --- a/app/views/index/index.volt +++ b/app/views/index/index.volt @@ -1,4 +1,3 @@ - {{ content() }}
diff --git a/app/views/invoices/index.volt b/app/views/invoices/index.volt index 0ed5aaf6..90b91d1a 100644 --- a/app/views/invoices/index.volt +++ b/app/views/invoices/index.volt @@ -41,4 +41,3 @@ - diff --git a/app/views/invoices/profile.volt b/app/views/invoices/profile.volt index db607d74..a0220ee2 100644 --- a/app/views/invoices/profile.volt +++ b/app/views/invoices/profile.volt @@ -1,4 +1,3 @@ - {{ content() }}
@@ -27,4 +26,4 @@ {{ link_to('invoices/index', 'Cancel') }}
-
\ No newline at end of file + diff --git a/app/views/layouts/companies.volt b/app/views/layouts/companies.volt index c4e713cd..60e5a47c 100644 --- a/app/views/layouts/companies.volt +++ b/app/views/layouts/companies.volt @@ -2,4 +2,4 @@
{{ content() }} -
\ No newline at end of file + diff --git a/app/views/layouts/invoices.volt b/app/views/layouts/invoices.volt index f12a1087..60e5a47c 100644 --- a/app/views/layouts/invoices.volt +++ b/app/views/layouts/invoices.volt @@ -1,4 +1,3 @@ - {{ elements.getTabs() }}
diff --git a/app/views/layouts/products.volt b/app/views/layouts/products.volt index f12a1087..60e5a47c 100644 --- a/app/views/layouts/products.volt +++ b/app/views/layouts/products.volt @@ -1,4 +1,3 @@ - {{ elements.getTabs() }}
diff --git a/app/views/layouts/producttypes.volt b/app/views/layouts/producttypes.volt index f12a1087..60e5a47c 100644 --- a/app/views/layouts/producttypes.volt +++ b/app/views/layouts/producttypes.volt @@ -1,4 +1,3 @@ - {{ elements.getTabs() }}
diff --git a/app/views/products/edit.volt b/app/views/products/edit.volt index 3ac74435..0ad1496f 100644 --- a/app/views/products/edit.volt +++ b/app/views/products/edit.volt @@ -1,4 +1,3 @@ - {{ form("products/save", 'role': 'form') }}
    diff --git a/app/views/products/index.volt b/app/views/products/index.volt index f690a475..1393729c 100644 --- a/app/views/products/index.volt +++ b/app/views/products/index.volt @@ -1,4 +1,3 @@ - {{ content() }}
    diff --git a/app/views/products/new.volt b/app/views/products/new.volt index 42aa8cf0..52c2a3b7 100644 --- a/app/views/products/new.volt +++ b/app/views/products/new.volt @@ -1,4 +1,3 @@ - {{ content() }} {{ form("products/create") }} diff --git a/app/views/products/search.volt b/app/views/products/search.volt index c3d394d8..700a2f19 100644 --- a/app/views/products/search.volt +++ b/app/views/products/search.volt @@ -11,8 +11,8 @@ {% for product in page.items %} {% if loop.first %} - - +
    + @@ -20,21 +20,21 @@ - - + + {% endif %} - - - - - - - - - + + + + + + + + + {% if loop.last %} - - + + - -
    Id Product TypePrice Active
    {{ product.id }}{{ product.getProductTypes().name }}{{ product.name }}${{ "%.2f"|format(product.price) }}{{ product.getActiveDetail() }}{{ link_to("products/edit/" ~ product.id, ' Edit', "class": "btn btn-default") }}{{ link_to("products/delete/" ~ product.id, ' Delete', "class": "btn btn-default") }}
    {{ product.id }}{{ product.getProductTypes().name }}{{ product.name }}${{ "%.2f"|format(product.price) }}{{ product.getActiveDetail() }}{{ link_to("products/edit/" ~ product.id, ' Edit', "class": "btn btn-default") }}{{ link_to("products/delete/" ~ product.id, ' Delete', "class": "btn btn-default") }}
    @@ -46,8 +46,8 @@
    + + {% endif %} {% else %} No products are recorded diff --git a/app/views/producttypes/edit.volt b/app/views/producttypes/edit.volt index f9abdd13..2c3e657c 100644 --- a/app/views/producttypes/edit.volt +++ b/app/views/producttypes/edit.volt @@ -1,34 +1,29 @@ {{ form("producttypes/save", 'role': 'form') }} - -
      - -
    • - {{ submit_button("Save", "class": "btn btn-success") }} -
    • -
    - -{{ content() }} - -

    Edit Product Types

    - -
    - -{% for element in form %} - {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} -{{ element }} - {% else %} -
    - {{ element.label(['class': 'control-label']) }} -
    - {{ element }} -
    -
    - {% endif %} -{% endfor %} - -
    - +
      + +
    • + {{ submit_button("Save", "class": "btn btn-success") }} +
    • +
    + + {{ content() }} + +

    Edit Product Types

    + +
    + {% for element in form %} + {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} + {{ element }} + {% else %} +
    + {{ element.label(['class': 'control-label']) }} +
    + {{ element }} +
    +
    + {% endif %} + {% endfor %} +
    - diff --git a/app/views/producttypes/index.volt b/app/views/producttypes/index.volt index f68960f1..071f183d 100644 --- a/app/views/producttypes/index.volt +++ b/app/views/producttypes/index.volt @@ -5,25 +5,21 @@
    {{ form("producttypes/search", "autocomplete": "off") }} - -
    - -

    Search product types

    - -
    - - {{ numeric_field("id", "size": 10, "maxlength": 10) }} -
    - -
    - - {{ text_field("name", "size": 24, "maxlength": 70) }} +
    +

    Search product types

    + +
    + + {{ numeric_field("id", "size": 10, "maxlength": 10) }} +
    + +
    + + {{ text_field("name", "size": 24, "maxlength": 70) }} +
    + +
    + {{ submit_button("Search", "class": "btn btn-primary") }} +
    - -
    - {{ submit_button("Search", "class": "btn btn-primary") }} -
    - -
    - diff --git a/app/views/producttypes/new.volt b/app/views/producttypes/new.volt index 095bbd27..616ce8f9 100644 --- a/app/views/producttypes/new.volt +++ b/app/views/producttypes/new.volt @@ -1,23 +1,21 @@ {{ form("producttypes/create", "autocomplete": "off") }} +
      + +
    • + {{ submit_button("Save", "class": "btn btn-success") }} +
    • +
    -
      - -
    • - {{ submit_button("Save", "class": "btn btn-success") }} -
    • -
    + {{ content() }} -{{ content() }} +
    +

    Create product types

    -
    -

    Create product types

    - -
    - - {{ text_field("name", "size": 24, "maxlength": 70) }} +
    + + {{ text_field("name", "size": 24, "maxlength": 70) }} +
    - -
    diff --git a/app/views/producttypes/search.volt b/app/views/producttypes/search.volt index 81b7118b..2e0826d3 100644 --- a/app/views/producttypes/search.volt +++ b/app/views/producttypes/search.volt @@ -11,24 +11,24 @@ {% for producttype in page.items %} {% if loop.first %} - - +
    + - - + + {% endif %} - - - - - - + + + + + + {% if loop.last %} - - + + - -
    Id Name
    {{ producttype.id }}{{ producttype.name }}{{ link_to("producttypes/edit/" ~ producttype.id, ' Edit', "class": "btn btn-default") }}{{ link_to("producttypes/delete/" ~ producttype.id, ' Delete', "class": "btn btn-default") }}
    {{ producttype.id }}{{ producttype.name }}{{ link_to("producttypes/edit/" ~ producttype.id, ' Edit', "class": "btn btn-default") }}{{ link_to("producttypes/delete/" ~ producttype.id, ' Delete', "class": "btn btn-default") }}
    @@ -40,8 +40,8 @@
    + + {% endif %} {% else %} No product types are recorded diff --git a/app/views/register/index.volt b/app/views/register/index.volt index d98b4a71..a1de68f5 100644 --- a/app/views/register/index.volt +++ b/app/views/register/index.volt @@ -1,4 +1,3 @@ - {{ content() }} {{ form('register', 'id': 'registerForm', 'onbeforesubmit': 'return false') }} -
    -
    {{ form.label('name', ['class': 'control-label']) }}
    @@ -67,6 +64,5 @@ {{ submit_button('Register', 'class': 'btn btn-primary', 'onclick': 'return SignUp.validate();') }}

    By signing up, you accept terms of use and privacy policy.

    -
    diff --git a/app/views/session/index.volt b/app/views/session/index.volt index 4132c0c0..38489f9d 100644 --- a/app/views/session/index.volt +++ b/app/views/session/index.volt @@ -1,8 +1,6 @@ - {{ content() }}
    -
    - @@ -45,5 +42,4 @@ {{ link_to('register', 'Sign Up', 'class': 'btn btn-primary btn-large btn-success') }}
    -
    From 713f2376689d2ce06f046984a59afcb3138a4ea9 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 23 Nov 2019 15:31:20 +0000 Subject: [PATCH 003/118] #76 - Add php_codesniffer and psalm dev packages --- composer.json | 4 +- phpcs.xml.dist | 13 +++++ psalm.xml | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 phpcs.xml.dist create mode 100644 psalm.xml diff --git a/composer.json b/composer.json index 2a7a6b2c..ae4fcb41 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,9 @@ }, "require-dev": { "codeception/codeception": "^3.1", - "phalcon/ide-stubs": "4.0.0-rc.2" + "phalcon/ide-stubs": "4.0.0-rc.2", + "squizlabs/php_codesniffer": "3.5", + "vimeo/psalm": "^3.6" }, "autoload": { "psr-4": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..686502a6 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,13 @@ + + + Phalcon Coding Standards + + + + + + + + app + public/index.php + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..be2f3c92 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 87f4395479bcc2008d56d9e1100a73cfe4a36019 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 23 Nov 2019 15:37:47 +0000 Subject: [PATCH 004/118] #76 - Add namespaces for each .php file --- app/Services.php | 16 ++++++++++------ app/config/config.ini | 1 - app/controllers/AboutController.php | 3 +++ app/controllers/CompaniesController.php | 3 +++ app/controllers/ContactController.php | 3 +++ app/controllers/ControllerBase.php | 4 +++- app/controllers/ErrorsController.php | 3 +++ app/controllers/IndexController.php | 3 +++ app/controllers/InvoicesController.php | 3 +++ app/controllers/ProductsController.php | 3 +++ app/controllers/ProducttypesController.php | 3 +++ app/controllers/RegisterController.php | 3 +++ app/controllers/SessionController.php | 3 +++ app/forms/CompaniesForm.php | 8 +++++--- app/forms/ContactForm.php | 7 +++++-- app/forms/ProductTypesForm.php | 3 +++ app/forms/ProductsForm.php | 10 ++++++---- app/forms/RegisterForm.php | 9 ++++++--- app/library/Base/Services.php | 1 + app/models/Companies.php | 3 +++ app/models/Contact.php | 5 ++++- app/models/ProductTypes.php | 3 +++ app/models/Products.php | 3 +++ app/models/Users.php | 3 +++ app/plugins/NotFoundPlugin.php | 19 +++++++++++-------- app/plugins/SecurityPlugin.php | 12 +++++++----- 26 files changed, 103 insertions(+), 34 deletions(-) diff --git a/app/Services.php b/app/Services.php index 34a8667e..c0add24c 100644 --- a/app/Services.php +++ b/app/Services.php @@ -1,14 +1,18 @@ tag->prependTitle('INVO | '); - $this->view->setTemplateAfter('main'); } } diff --git a/app/controllers/ErrorsController.php b/app/controllers/ErrorsController.php index 6f15594c..25bb2085 100644 --- a/app/controllers/ErrorsController.php +++ b/app/controllers/ErrorsController.php @@ -1,4 +1,7 @@ getMessage() . PHP_EOL . $exception->getTraceAsString() @@ -29,8 +32,8 @@ public function beforeException(Event $event, MvcDispatcher $dispatcher, \Except if ($exception instanceof DispatcherException) { switch ($exception->getCode()) { - case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND: - case Dispatcher::EXCEPTION_ACTION_NOT_FOUND: + case MvcDispatcher::EXCEPTION_HANDLER_NOT_FOUND: + case MvcDispatcher::EXCEPTION_ACTION_NOT_FOUND: $dispatcher->forward( [ 'controller' => 'errors', diff --git a/app/plugins/SecurityPlugin.php b/app/plugins/SecurityPlugin.php index 5e43298e..4a410778 100644 --- a/app/plugins/SecurityPlugin.php +++ b/app/plugins/SecurityPlugin.php @@ -1,19 +1,21 @@ Date: Sat, 23 Nov 2019 16:42:01 +0000 Subject: [PATCH 005/118] #76 - Refactor of controllers --- app/controllers/AboutController.php | 6 +- app/controllers/CompaniesController.php | 42 ++-- app/controllers/ContactController.php | 59 +++--- app/controllers/IndexController.php | 14 +- app/controllers/InvoicesController.php | 36 ++-- app/controllers/ProductsController.php | 212 ++++++++----------- app/controllers/ProducttypesController.php | 230 +++++++++------------ app/controllers/RegisterController.php | 38 ++-- app/controllers/SessionController.php | 96 ++++----- 9 files changed, 295 insertions(+), 438 deletions(-) diff --git a/app/controllers/AboutController.php b/app/controllers/AboutController.php index eca2c802..bcb691cc 100644 --- a/app/controllers/AboutController.php +++ b/app/controllers/AboutController.php @@ -7,12 +7,12 @@ class AboutController extends ControllerBase { public function initialize() { - $this->tag->setTitle('About us'); - parent::initialize(); + + $this->tag->setTitle('About us'); } - public function indexAction() + public function indexAction(): void { } } diff --git a/app/controllers/CompaniesController.php b/app/controllers/CompaniesController.php index fa24e05c..229f4f0b 100644 --- a/app/controllers/CompaniesController.php +++ b/app/controllers/CompaniesController.php @@ -3,6 +3,8 @@ namespace Invo\Controllers; +use Invo\Forms\CompaniesForm; +use Invo\Models\Companies; use Phalcon\Mvc\Model\Criteria; use Phalcon\Paginator\Adapter\Model as Paginator; @@ -10,9 +12,9 @@ class CompaniesController extends ControllerBase { public function initialize() { - $this->tag->setTitle('Manage your companies'); - parent::initialize(); + + $this->tag->setTitle('Manage your companies'); } /** @@ -21,7 +23,6 @@ public function initialize() public function indexAction() { $this->session->conditions = null; - $this->view->form = new CompaniesForm; } @@ -77,40 +78,29 @@ public function searchAction() */ public function newAction() { - $this->view->form = new CompaniesForm( - null, - [ - 'edit' => true, - ] - ); + $this->view->form = new CompaniesForm(null, ['edit' => true]); } /** * Edits a company based on its id + * + * @param int $id */ public function editAction($id) { - if (!$this->request->isPost()) { - $company = Companies::findFirstById($id); - - if (!$company) { - $this->flash->error("Company was not found"); - - return $this->dispatcher->forward( - [ - "controller" => "companies", - "action" => "index", - ] - ); - } + $company = Companies::findFirstById($id); + if (!$company) { + $this->flash->error('Company was not found'); - $this->view->form = new CompaniesForm( - $company, + return $this->dispatcher->forward( [ - 'edit' => true, + "controller" => "companies", + "action" => "index", ] ); } + + $this->view->form = new CompaniesForm($company, ['edit' => true]); } /** @@ -146,7 +136,7 @@ public function createAction() if ($company->save() == false) { foreach ($company->getMessages() as $message) { - $this->flash->error($message); + $this->flash->error((string)$message); } return $this->dispatcher->forward( diff --git a/app/controllers/ContactController.php b/app/controllers/ContactController.php index 0e69068a..9d481e4a 100644 --- a/app/controllers/ContactController.php +++ b/app/controllers/ContactController.php @@ -3,6 +3,9 @@ namespace Invo\Controllers; +use Invo\Forms\ContactForm; +use Invo\Models\Contact; + /** * ContactController * @@ -12,12 +15,12 @@ class ContactController extends ControllerBase { public function initialize() { - $this->tag->setTitle('Contact us'); - parent::initialize(); + + $this->tag->setTitle('Contact us'); } - public function indexAction() + public function indexAction(): void { $this->view->form = new ContactForm; } @@ -27,13 +30,11 @@ public function indexAction() */ public function sendAction() { - if ($this->request->isPost() != true) { - return $this->dispatcher->forward( - [ - "controller" => "contact", - "action" => "index", - ] - ); + if (!$this->request->isPost()) { + return $this->dispatcher->forward([ + 'controller' => 'contact', + 'action' => 'index', + ]); } $form = new ContactForm; @@ -47,36 +48,28 @@ public function sendAction() $this->flash->error($message); } - return $this->dispatcher->forward( - [ - "controller" => "contact", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'contact', + 'action' => 'index', + ]); } - if ($contact->save() == false) { + if (!$contact->save()) { foreach ($contact->getMessages() as $message) { - $this->flash->error($message); + $this->flash->error((string)$message); } - return $this->dispatcher->forward( - [ - "controller" => "contact", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'contact', + 'action' => 'index', + ]); } - $this->flash->success( - 'Thanks, we will contact you in the next few hours' - ); + $this->flash->success('Thanks, we will contact you in the next few hours'); - return $this->dispatcher->forward( - [ - "controller" => "index", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'index', + 'action' => 'index', + ]); } } diff --git a/app/controllers/IndexController.php b/app/controllers/IndexController.php index b909eb02..bfc0bfcb 100644 --- a/app/controllers/IndexController.php +++ b/app/controllers/IndexController.php @@ -7,18 +7,16 @@ class IndexController extends ControllerBase { public function initialize() { - $this->tag->setTitle('Welcome'); - parent::initialize(); + + $this->tag->setTitle('Welcome'); } - public function indexAction() + public function indexAction(): void { - if (!$this->request->isPost()) { - $this->flash->notice( - 'This is a sample application of the Phalcon Framework. + $this->flash->notice( + 'This is a sample application of the Phalcon Framework. Please don\'t provide us any personal information. Thanks' - ); - } + ); } } diff --git a/app/controllers/InvoicesController.php b/app/controllers/InvoicesController.php index 69ac8aad..cc4b6392 100644 --- a/app/controllers/InvoicesController.php +++ b/app/controllers/InvoicesController.php @@ -3,13 +3,12 @@ namespace Invo\Controllers; -use Phalcon\Flash; -use Phalcon\Session; +use Invo\Models\Users; /** * InvoicesController * - * Manage operations for invoises + * Manage operations for invoices */ class InvoicesController extends ControllerBase { @@ -20,7 +19,7 @@ public function initialize() parent::initialize(); } - public function indexAction() + public function indexAction(): void { } @@ -34,35 +33,26 @@ public function profileAction() //Query the active user $user = Users::findFirst($auth['id']); - if ($user == false) { - return $this->dispatcher->forward( - [ - "controller" => "index", - "action" => "index", - ] - ); + if (!$user) { + return $this->dispatcher->forward([ + 'controller' => 'index', + 'action' => 'index', + ]); } if (!$this->request->isPost()) { $this->tag->setDefault('name', $user->name); $this->tag->setDefault('email', $user->email); } else { - $name = $this->request->getPost('name', ['string', 'striptags']); - $email = $this->request->getPost('email', 'email'); + $user->name = $this->request->getPost('name', ['string', 'striptags']); + $user->email = $this->request->getPost('email', 'email'); - $user->name = $name; - $user->email = $email; - - if ($user->save() == false) { + if (!$user->save()) { foreach ($user->getMessages() as $message) { - $this->flash->error( - (string) $message - ); + $this->flash->error((string) $message); } } else { - $this->flash->success( - 'Your profile information was updated successfully' - ); + $this->flash->success('Your profile information was updated successfully'); } } } diff --git a/app/controllers/ProductsController.php b/app/controllers/ProductsController.php index 3565f70a..c4b540c4 100644 --- a/app/controllers/ProductsController.php +++ b/app/controllers/ProductsController.php @@ -3,6 +3,7 @@ namespace Invo\Controllers; +use Invo\Models\Products; use Phalcon\Mvc\Model\Criteria; use Phalcon\Paginator\Adapter\Model as Paginator; @@ -15,18 +16,17 @@ class ProductsController extends ControllerBase { public function initialize() { - $this->tag->setTitle('Manage your products'); - parent::initialize(); + + $this->tag->setTitle('Manage your products'); } /** * Shows the index action */ - public function indexAction() + public function indexAction(): void { $this->session->conditions = null; - $this->view->form = new ProductsForm; } @@ -57,21 +57,17 @@ public function searchAction() if (count($products) == 0) { $this->flash->notice("The search did not find any products"); - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } - $paginator = new Paginator( - [ - "data" => $products, - "limit" => 10, - "page" => $numberPage, - ] - ); + $paginator = new Paginator([ + 'data' => $products, + 'limit' => 10, + 'page' => $numberPage, + ]); $this->view->page = $paginator->getPaginate(); } @@ -79,42 +75,29 @@ public function searchAction() /** * Shows the form to create a new product */ - public function newAction() + public function newAction(): void { - $this->view->form = new ProductsForm( - null, - [ - 'edit' => true, - ] - ); + $this->view->form = new ProductsForm(null, ['edit' => true]); } /** * Edits a product based on its id + * + * @param $id */ - public function editAction($id) + public function editAction($id): void { - if (!$this->request->isPost()) { - $product = Products::findFirstById($id); - - if (!$product) { - $this->flash->error("Product was not found"); - - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); - } + $product = Products::findFirstById($id); + if (!$product) { + $this->flash->error('Product was not found'); - $this->view->form = new ProductsForm( - $product, - [ - 'edit' => true, - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } + + $this->view->form = new ProductsForm($product, ['edit' => true]); } /** @@ -141,74 +124,57 @@ public function createAction() $this->flash->error($message); } - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "new", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'new', + ]); } - if ($product->save() == false) { + if (!$product->save()) { foreach ($product->getMessages() as $message) { - $this->flash->error($message); + $this->flash->error((string)$message); } - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "new", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'new', + ]); } $form->clear(); + $this->flash->success('Product was created successfully'); - $this->flash->success("Product was created successfully"); - - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } /** * Saves current product in screen - * - * @param string $id */ public function saveAction() { if (!$this->request->isPost()) { - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } - $id = $this->request->getPost("id", "int"); - + $id = $this->request->getPost('id', 'int'); $product = Products::findFirstById($id); - if (!$product) { - $this->flash->error("Product does not exist"); + $this->flash->error('Product does not exist'); - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } $form = new ProductsForm; - $this->view->form = $form; - $data = $this->request->getPost(); if (!$form->isValid($data, $product)) { @@ -216,39 +182,32 @@ public function saveAction() $this->flash->error($message); } - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "edit", - "params" => [$id] - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'edit', + 'params' => [$id], + ]); } - if ($product->save() == false) { + if (!$product->save()) { foreach ($product->getMessages() as $message) { $this->flash->error($message); } - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "edit", - "params" => [$id] - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'edit', + 'params' => [$id], + ]); } $form->clear(); + $this->flash->success('Product was updated successfully'); - $this->flash->success("Product was updated successfully"); - - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } /** @@ -259,16 +218,13 @@ public function saveAction() public function deleteAction($id) { $products = Products::findFirstById($id); - if (!$products) { - $this->flash->error("Product was not found"); + $this->flash->error('Product was not found'); - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } if (!$products->delete()) { @@ -276,21 +232,17 @@ public function deleteAction($id) $this->flash->error($message); } - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "search", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'search', + ]); } - $this->flash->success("Product was deleted"); + $this->flash->success('Product was deleted'); - return $this->dispatcher->forward( - [ - "controller" => "products", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'products', + 'action' => 'index', + ]); } } diff --git a/app/controllers/ProducttypesController.php b/app/controllers/ProducttypesController.php index 924edc81..a4ed4002 100644 --- a/app/controllers/ProducttypesController.php +++ b/app/controllers/ProducttypesController.php @@ -3,6 +3,8 @@ namespace Invo\Controllers; +use Invo\Forms\ProductTypesForm; +use Invo\Models\ProductTypes; use Phalcon\Mvc\Model\Criteria; use Phalcon\Paginator\Adapter\Model as Paginator; @@ -23,10 +25,9 @@ public function initialize() /** * Shows the index action */ - public function indexAction() + public function indexAction(): void { $this->session->conditions = null; - $this->view->form = new ProductTypesForm; } @@ -39,13 +40,13 @@ public function searchAction() if ($this->request->isPost()) { $query = Criteria::fromInput( $this->di, - "ProductTypes", + 'ProductTypes', $this->request->getPost() ); $this->persistent->searchParams = $query->getParams(); } else { - $numberPage = $this->request->getQuery("page", "int"); + $numberPage = $this->request->getQuery('page', 'int'); } $parameters = []; @@ -54,25 +55,20 @@ public function searchAction() } $productTypes = ProductTypes::find($parameters); + if (count($productTypes) === 0) { + $this->flash->notice('The search did not find any product types'); - if (count($productTypes) == 0) { - $this->flash->notice("The search did not find any product types"); - - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } - $paginator = new Paginator( - [ - "data" => $productTypes, - "limit" => 10, - "page" => $numberPage, - ] - ); + $paginator = new Paginator([ + 'data' => $productTypes, + 'limit' => 10, + 'page' => $numberPage, + ]); $this->view->page = $paginator->getPaginate(); $this->view->productTypes = $productTypes; @@ -81,42 +77,29 @@ public function searchAction() /** * Shows the form to create a new producttype */ - public function newAction() + public function newAction(): void { - $this->view->form = new ProductTypesForm( - null, - [ - 'edit' => true, - ] - ); + $this->view->form = new ProductTypesForm(null, ['edit' => true]); } /** * Edits a producttype based on its id + * + * @param int $id */ public function editAction($id) { - if (!$this->request->isPost()) { - $producttypes = ProductTypes::findFirstById($id); - - if (!$producttypes) { - $this->flash->error("Product type to edit was not found"); - - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); - } + $productTypes = ProductTypes::findFirstById($id); + if (!$productTypes) { + $this->flash->error('Product type to edit was not found'); - $this->view->form = new ProductTypesForm( - $producttypes, - [ - 'edit' => true, - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } + + $this->view->form = new ProductTypesForm($productTypes, ['edit' => true]); } /** @@ -125,165 +108,136 @@ public function editAction($id) public function createAction() { if (!$this->request->isPost()) { - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } $form = new ProductTypesForm; - $producttypes = new ProductTypes(); + $productTypes = new ProductTypes(); $data = $this->request->getPost(); - if (!$form->isValid($data, $producttypes)) { + if (!$form->isValid($data, $productTypes)) { foreach ($form->getMessages() as $message) { - $this->flash->error($message); + $this->flash->error((string)$message); } - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "new", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'new', + ]); } - if ($producttypes->save() == false) { - foreach ($producttypes->getMessages() as $message) { - $this->flash->error($message); + if (!$productTypes->save()) { + foreach ($productTypes->getMessages() as $message) { + $this->flash->error((string)$message); } - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "new", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'new', + ]); } $form->clear(); + $this->flash->success('Product type was created successfully'); - $this->flash->success("Product type was created successfully"); - - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } /** * Saves current producttypes in screen - * - * @param string $id */ public function saveAction() { if (!$this->request->isPost()) { - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } - $id = $this->request->getPost("id", "int"); + $id = $this->request->getPost('id', 'int'); $productTypes = ProductTypes::findFirstById($id); if (!$productTypes) { - $this->flash->error("productTypes does not exist"); + $this->flash->error('productTypes does not exist'); - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } $form = new ProductTypesForm; - $data = $this->request->getPost(); if (!$form->isValid($data, $productTypes)) { foreach ($form->getMessages() as $message) { $this->flash->error($message); } - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "new", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'new', + ]); } - if ($productTypes->save() == false) { + if (!$productTypes->save()) { foreach ($productTypes->getMessages() as $message) { $this->flash->error($message); } - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "new", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'new', + ]); } $form->clear(); + $this->flash->success('Product Type was updated successfully'); - $this->flash->success("Product Type was updated successfully"); - - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } /** * Deletes a producttypes * - * @param string $id + * @param int $id */ public function deleteAction($id) { $productTypes = ProductTypes::findFirstById($id); if (!$productTypes) { - $this->flash->error("Product types was not found"); + $this->flash->error('Product types was not found'); - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } if (!$productTypes->delete()) { foreach ($productTypes->getMessages() as $message) { - $this->flash->error($message); + $this->flash->error((string)$message); } - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "search", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'search', + ]); } - $this->flash->success("product types was deleted"); + $this->flash->success('product types was deleted'); - return $this->dispatcher->forward( - [ - "controller" => "producttypes", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'producttypes', + 'action' => 'index', + ]); } } diff --git a/app/controllers/RegisterController.php b/app/controllers/RegisterController.php index bf141916..70a9c65a 100644 --- a/app/controllers/RegisterController.php +++ b/app/controllers/RegisterController.php @@ -3,6 +3,10 @@ namespace Invo\Controllers; +use Invo\Forms\RegisterForm; +use Invo\Models\Users; +use Phalcon\Db\RawValue; + /** * SessionController * @@ -25,47 +29,37 @@ public function indexAction() $form = new RegisterForm; if ($this->request->isPost()) { - $name = $this->request->getPost('name', ['string', 'striptags']); - $username = $this->request->getPost('username', 'alphanum'); - $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); - if ($password != $repeatPassword) { + if ($password !== $repeatPassword) { $this->flash->error('Passwords are different'); return false; } $user = new Users(); - - $user->username = $username; + $user->username = $this->request->getPost('username', 'alphanum'); $user->password = sha1($password); - $user->name = $name; - $user->email = $email; - $user->created_at = new Phalcon\Db\RawValue('now()'); + $user->name = $this->request->getPost('name', ['string', 'striptags']); + $user->email = $this->request->getPost('email', 'email'); + $user->created_at = new RawValue('now()'); $user->active = 'Y'; - if ($user->save() == false) { + if (!$user->save()) { foreach ($user->getMessages() as $message) { - $this->flash->error( - (string) $message - ); + $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); - $this->flash->success( - 'Thanks for sign-up, please log-in to start generating invoices' - ); + $this->flash->success('Thanks for sign-up, please log-in to start generating invoices'); - return $this->dispatcher->forward( - [ - "controller" => "session", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'session', + 'action' => 'index', + ]); } } diff --git a/app/controllers/SessionController.php b/app/controllers/SessionController.php index ba1b5931..a881abe5 100644 --- a/app/controllers/SessionController.php +++ b/app/controllers/SessionController.php @@ -3,6 +3,8 @@ namespace Invo\Controllers; +use Invo\Models\Users; + /** * SessionController * @@ -12,33 +14,15 @@ class SessionController extends ControllerBase { public function initialize() { - $this->tag->setTitle('Sign Up/Sign In'); - parent::initialize(); - } - public function indexAction() - { - if (!$this->request->isPost()) { - $this->tag->setDefault('email', 'demo'); - $this->tag->setDefault('password', 'phalcon'); - } + $this->tag->setTitle('Sign Up/Sign In'); } - /** - * Register an authenticated user into session data - * - * @param Users $user - */ - private function _registerSession(Users $user) + public function indexAction(): void { - $this->session->set( - 'auth', - [ - 'id' => $user->id, - 'name' => $user->name, - ] - ); + $this->tag->setDefault('email', 'demo'); + $this->tag->setDefault('password', 'phalcon'); } /** @@ -50,56 +34,58 @@ public function startAction() $email = $this->request->getPost('email'); $password = $this->request->getPost('password'); - $user = Users::findFirst( - [ - "(email = :email: OR username = :email:) AND password = :password: AND active = 'Y'", - 'bind' => [ - 'email' => $email, - 'password' => sha1($password), - ] - ] - ); - - if ($user != false) { - $this->_registerSession($user); + /** @var Users $user */ + $user = Users::findFirst([ + "(email = :email: OR username = :email:) AND password = :password: AND active = 'Y'", + 'bind' => [ + 'email' => $email, + 'password' => sha1($password), + ], + ]); + if ($user) { + $this->registerSession($user); $this->flash->success('Welcome ' . $user->name); - return $this->dispatcher->forward( - [ - "controller" => "invoices", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'invoices', + 'action' => 'index', + ]); } $this->flash->error('Wrong email/password'); } - return $this->dispatcher->forward( - [ - "controller" => "session", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'session', + 'action' => 'index', + ]); } /** * Finishes the active session redirecting to the index - * - * @return unknown */ public function endAction() { $this->session->remove('auth'); - $this->flash->success('Goodbye!'); - return $this->dispatcher->forward( - [ - "controller" => "index", - "action" => "index", - ] - ); + return $this->dispatcher->forward([ + 'controller' => 'index', + 'action' => 'index', + ]); + } + + /** + * Register an authenticated user into session data + * + * @param Users $user + */ + private function registerSession(Users $user) + { + $this->session->set('auth', [ + 'id' => $user->id, + 'name' => $user->name, + ]); } } From 37886618cea4ed340e3bf0587e6e9afe8ce37121 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 23 Nov 2019 16:57:00 +0000 Subject: [PATCH 006/118] #76 - Refactor of forms --- app/forms/CompaniesForm.php | 140 +++++++++++---------------------- app/forms/ContactForm.php | 60 ++++++-------- app/forms/ProductTypesForm.php | 29 +++---- app/forms/ProductsForm.php | 64 +++++++-------- app/forms/RegisterForm.php | 95 ++++++++++------------ 5 files changed, 152 insertions(+), 236 deletions(-) diff --git a/app/forms/CompaniesForm.php b/app/forms/CompaniesForm.php index f0cebf1c..2bb9fe16 100644 --- a/app/forms/CompaniesForm.php +++ b/app/forms/CompaniesForm.php @@ -12,116 +12,68 @@ class CompaniesForm extends Form { /** * Initialize the companies form + * + * @param null $entity + * @param array $options */ public function initialize($entity = null, array $options = []) { if (!isset($options['edit'])) { - $element = new Text("id"); - - $this->add( - $element->setLabel("Id") - ); + $this->add((new Text('id'))->setLabel('Id')); } else { - $this->add( - new Hidden("id") - ); + $this->add(new Hidden('id')); } - $name = new Text("name"); - - $name->setLabel("Name"); - - $name->setFilters( - [ - 'striptags', - 'string', - ] - ); - - $name->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Name is required', - ] - ), - ] - ); + $commonFilters = [ + 'striptags', + 'string', + ]; + + /** + * Name text field + */ + $name = new Text('name'); + $name->setLabel('Name'); + $name->setFilters($commonFilters); + $name->addValidators([ + new PresenceOf(['message' => 'Name is required']), + ]); $this->add($name); - - - $telephone = new Text("telephone"); - - $telephone->setLabel("Telephone"); - - $telephone->setFilters( - [ - 'striptags', - 'string', - ] - ); - - $telephone->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Telephone is required', - ] - ), - ] - ); + /** + * Telephone text field + */ + $telephone = new Text('telephone'); + $telephone->setLabel('Telephone'); + $telephone->setFilters($commonFilters); + $telephone->addValidators([ + new PresenceOf(['message' => 'Telephone is required']), + ]); $this->add($telephone); - - - $address = new Text("address"); - - $address->setLabel("address"); - - $address->setFilters( - [ - 'striptags', - 'string', - ] - ); - - $address->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Address is required', - ] - ), - ] - ); + /** + * Address text field + */ + $address = new Text('address'); + $address->setLabel('address'); + $address->setFilters($commonFilters); + $address->addValidators([ + new PresenceOf(['message' => 'Address is required']), + ]); $this->add($address); - - - $city = new Text("city"); - - $city->setLabel("city"); - - $city->setFilters( - [ - 'striptags', - 'string', - ] - ); - - $city->addValidators( - [ - new PresenceOf( - [ - 'message' => 'City is required', - ] - ), - ] - ); + /** + * City text field + */ + $city = new Text('city'); + $city->setLabel('city'); + $city->setFilters($commonFilters); + $city->addValidators([ + new PresenceOf(['message' => 'City is required']), + ]); $this->add($city); } diff --git a/app/forms/ContactForm.php b/app/forms/ContactForm.php index 418e8c33..5fb3a782 100644 --- a/app/forms/ContactForm.php +++ b/app/forms/ContactForm.php @@ -11,55 +11,47 @@ class ContactForm extends Form { + /** + * @param null $entity + * @param array $options + */ public function initialize($entity = null, array $options = []) { - // Name + /** + * Name text field + */ $name = new Text('name'); $name->setLabel('Your Full Name'); $name->setFilters(['striptags', 'string']); - $name->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Name is required', - ] - ), - ] - ); + $name->addValidators([ + new PresenceOf(['message' => 'Name is required']), + ]); + $this->add($name); - // Email + /** + * Email field + */ $email = new Text('email'); $email->setLabel('E-Mail'); $email->setFilters('email'); - $email->addValidators( - [ - new PresenceOf( - [ - 'message' => 'E-mail is required', - ] - ), - new Email( - [ - 'message' => 'E-mail is not valid', - ] - ) - ] - ); + $email->addValidators([ + new PresenceOf(['message' => 'E-mail is required']), + new Email(['message' => 'E-mail is not valid']) + ]); + $this->add($email); + /** + * Comment textarea + */ $comments = new TextArea('comments'); $comments->setLabel('Comments'); $comments->setFilters(['striptags', 'string']); - $comments->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Comments is required', - ] - ), - ] - ); + $comments->addValidators([ + new PresenceOf(['message' => 'Comments is required']), + ]); + $this->add($comments); } } diff --git a/app/forms/ProductTypesForm.php b/app/forms/ProductTypesForm.php index 20d8fb5a..57a9e5d6 100644 --- a/app/forms/ProductTypesForm.php +++ b/app/forms/ProductTypesForm.php @@ -12,32 +12,25 @@ class ProductTypesForm extends Form { /** * Initialize the products form + * + * @param null $entity + * @param array $options */ public function initialize($entity = null, array $options = []) { if (!isset($options['edit'])) { - $element = new Text("id"); - $this->add( - $element->setLabel("Id") - ); + $this->add((new Text('id'))->setLabel('Id')); } else { - $this->add( - new Hidden("id") - ); + $this->add(new Hidden('id')); } - $name = new Text("name"); - $name->setLabel("Name"); + $name = new Text('name'); + $name->setLabel('Name'); $name->setFilters(['striptags', 'string']); - $name->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Name is required', - ] - ), - ] - ); + $name->addValidators([ + new PresenceOf(['message' => 'Name is required']), + ]); + $this->add($name); } } diff --git a/app/forms/ProductsForm.php b/app/forms/ProductsForm.php index 2afdc5e1..6ed399a3 100644 --- a/app/forms/ProductsForm.php +++ b/app/forms/ProductsForm.php @@ -3,6 +3,7 @@ namespace Invo\Controllers; +use Invo\Models\ProductTypes; use Phalcon\Forms\Element\Hidden; use Phalcon\Forms\Element\Select; use Phalcon\Forms\Element\Text; @@ -14,35 +15,33 @@ class ProductsForm extends Form { /** * Initialize the products form + * + * @param null $entity + * @param array $options */ public function initialize($entity = null, array $options = []) { if (!isset($options['edit'])) { - $element = new Text("id"); - - $this->add( - $element->setLabel("Id") - ); + $this->add((new Text('id'))->setLabel('Id')); } else { - $this->add( - new Hidden("id") - ); + $this->add(new Hidden('id')); } - $name = new Text("name"); - $name->setLabel("Name"); + /** + * Name text field + */ + $name = new Text('name'); + $name->setLabel('Name'); $name->setFilters(['striptags', 'string']); - $name->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Name is required', - ] - ), - ] - ); + $name->addValidators([ + new PresenceOf(['message' => 'Name is required']), + ]); + $this->add($name); + /** + * Product Type Id Select + */ $type = new Select( 'product_types_id', ProductTypes::find(), @@ -54,25 +53,20 @@ public function initialize($entity = null, array $options = []) ] ); $type->setLabel('Type'); + $this->add($type); - $price = new Text("price"); - $price->setLabel("Price"); + /** + * Price text field + */ + $price = new Text('price'); + $price->setLabel('Price'); $price->setFilters(['float']); - $price->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Price is required', - ] - ), - new Numericality( - [ - 'message' => 'Price is required', - ] - ), - ] - ); + $price->addValidators([ + new PresenceOf(['message' => 'Price is required']), + new Numericality(['message' => 'Price is required']), + ]); + $this->add($price); } } diff --git a/app/forms/RegisterForm.php b/app/forms/RegisterForm.php index fef8bb30..38d518ce 100644 --- a/app/forms/RegisterForm.php +++ b/app/forms/RegisterForm.php @@ -11,84 +11,69 @@ class RegisterForm extends Form { + /** + * @param null $entity + * @param null $options + */ public function initialize($entity = null, $options = null) { - // Name + /** + * Name text field + */ $name = new Text('name'); $name->setLabel('Your Full Name'); $name->setFilters(['striptags', 'string']); - $name->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Name is required', - ] - ), - ] - ); + $name->addValidators([ + new PresenceOf(['message' => 'Name is required']), + ]); + $this->add($name); - // Name + /** + * Username text field + */ $name = new Text('username'); $name->setLabel('Username'); $name->setFilters(['alpha']); - $name->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Please enter your desired user name', - ] - ), - ] - ); + $name->addValidators([ + new PresenceOf(['message' => 'Please enter your desired user name']), + ]); + $this->add($name); - // Email + /** + * Email text field + */ $email = new Text('email'); $email->setLabel('E-Mail'); $email->setFilters('email'); - $email->addValidators( - [ - new PresenceOf( - [ - 'message' => 'E-mail is required', - ] - ), - new Email( - [ - 'message' => 'E-mail is not valid', - ] - ), - ] - ); + $email->addValidators([ + new PresenceOf(['message' => 'E-mail is required']), + new Email(['message' => 'E-mail is not valid']), + ]); + $this->add($email); - // Password + /** + * Password field + */ $password = new Password('password'); $password->setLabel('Password'); - $password->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Password is required', - ] - ), - ] - ); + $password->addValidators([ + new PresenceOf(['message' => 'Password is required']), + ]); + $this->add($password); - // Confirm Password + /** + * Confirm Password field + */ $repeatPassword = new Password('repeatPassword'); $repeatPassword->setLabel('Repeat Password'); - $repeatPassword->addValidators( - [ - new PresenceOf( - [ - 'message' => 'Confirmation password is required', - ] - ), - ] - ); + $repeatPassword->addValidators([ + new PresenceOf(['message' => 'Confirmation password is required']), + ]); + $this->add($repeatPassword); } } From 3052d8abfa851cecbb4947fe27fc61fe0820c037 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 23 Nov 2019 16:57:24 +0000 Subject: [PATCH 007/118] #76 - Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index cdf965e4..f69bddad 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ Thumbs.db *.sublime-project *.sublime-workspace .idea/ +vendor/ +composer.lock +composer.phar From 9dc72b351a6c06c7b39218913ede5aed777fe168 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 23 Nov 2019 17:23:52 +0000 Subject: [PATCH 008/118] #76 - Fix errors --- app/config/loader.php | 8 +++---- app/library/Elements.php | 19 ++++++++------- app/models/Products.php | 8 ++----- app/plugins/SecurityPlugin.php | 44 +++++++++++++--------------------- psalm.xml | 1 + public/index.php | 27 +++++---------------- 6 files changed, 39 insertions(+), 68 deletions(-) diff --git a/app/config/loader.php b/app/config/loader.php index 1b7317b5..b545424f 100644 --- a/app/config/loader.php +++ b/app/config/loader.php @@ -13,8 +13,6 @@ APP_PATH . $config->application->formsDir, ])->register(); -$loader->registerClasses( - [ - 'Services' => APP_PATH . 'app/Services.php', - ] -); +$loader->registerClasses([ + 'Services' => APP_PATH . 'app/Services.php', +]); diff --git a/app/library/Elements.php b/app/library/Elements.php index 5d5702dc..1ab27cc8 100644 --- a/app/library/Elements.php +++ b/app/library/Elements.php @@ -1,15 +1,18 @@ [ 'index' => [ 'caption' => 'Home', @@ -36,7 +39,7 @@ class Elements extends Component ] ]; - private $_tabs = [ + private $tabs = [ 'Invoices' => [ 'controller' => 'invoices', 'action' => 'index', @@ -73,16 +76,16 @@ public function getMenu() { $auth = $this->session->get('auth'); if ($auth) { - $this->_headerMenu['navbar-right']['session'] = [ + $this->headerMenu['navbar-right']['session'] = [ 'caption' => 'Log Out', 'action' => 'end' ]; } else { - unset($this->_headerMenu['navbar-left']['invoices']); + unset($this->headerMenu['navbar-left']['invoices']); } $controllerName = $this->view->getControllerName(); - foreach ($this->_headerMenu as $position => $menu) { + foreach ($this->headerMenu as $position => $menu) { echo ' {% endif %} {% endfor %} - diff --git a/themes/invo/companies/search.volt b/themes/invo/companies/search.volt index 82a545f8..b23dfdc6 100644 --- a/themes/invo/companies/search.volt +++ b/themes/invo/companies/search.volt @@ -1,5 +1,3 @@ -{{ content() }} -