Skip to content

Commit e6829bb

Browse files
authored
Merge pull request #34 from ModySolutions/remove-unnecessary-static-methods
Remove unnecessary static methods
2 parents 014073a + 8063c7d commit e6829bb

56 files changed

Lines changed: 2457 additions & 1122 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ],
3+
"globals" : {
4+
"Invoice": "readonly",
5+
"location": "readonly"
6+
},
7+
"settings": {
8+
"react": {
9+
"version": "18.3.1"
10+
}
11+
}
12+
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ jobs:
4747
restore-keys: |
4848
node_modules-${{ runner.os }}-
4949
50-
- name: Install pnpm
51-
uses: pnpm/action-setup@v4
52-
with:
53-
version: 10
54-
5550
- name: nvm use ${{ matrix.node-version }}
5651
uses: actions/setup-node@v4
5752
with:

.github/workflows/lint.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Verify Coding Standards
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- dev
8+
9+
jobs:
10+
web-deploy:
11+
name: 🎉 Verify Coding Standards
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: 🚚 Get latest code
15+
uses: actions/checkout@v3
16+
17+
- name: Cache Vendor
18+
id: cache-vendor
19+
uses: actions/cache@v3
20+
env:
21+
cache-name: cache-vendors
22+
with:
23+
path: vendor
24+
key: vendor-${{ runner.os }}-${{ hashFiles('composer.lock') }}
25+
restore-keys: |
26+
vendor-${{ runner.os }}-
27+
28+
- name: Cache Node Modules
29+
id: cache-node_modules
30+
uses: actions/cache@v3
31+
env:
32+
cache-name: cache-node_modules
33+
with:
34+
path: node_modules
35+
key: node_modules-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
36+
restore-keys: |
37+
node_modules-${{ runner.os }}-
38+
39+
- name: Composer Install
40+
run: composer install
41+
if: steps.cache-vendor.outputs.cache-hit != 'true'
42+
43+
- name: Setup pnpm
44+
uses: pnpm/action-setup@v4
45+
with:
46+
version: 10
47+
48+
- name: nvm use ${{ matrix.node-version }}
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: ${{ matrix.node-version }}
52+
cache: 'pnpm'
53+
54+
- name: pnpm install
55+
run: pnpm install
56+
if: steps.cache-node_modules.outputs.cache-hit != 'true'
57+
58+
- name: lint
59+
run: pnpm lint

app/Features/Invoice.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Invoice\Features;
4+
5+
trait Invoice
6+
{
7+
public function get_invoice($invoice_id): \WP_Post {}
8+
}

app/Features/Post.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Invoice\Features;
4+
5+
trait Post
6+
{
7+
public function get_statuses_array(): array
8+
{
9+
return [
10+
'draft' => [
11+
'label' => _x('Draft', 'invoice post status'),
12+
'public' => true,
13+
'show_in_admin_all_list' => true,
14+
'show_in_admin_status_list' => true,
15+
'date_floating' => true,
16+
'label_count' => _n_noop(
17+
'Draft <span class="count">(%s)</span>',
18+
'Drafts <span class="count">(%s)</span>',
19+
),
20+
],
21+
'invoice_issued' => [
22+
'label' => _x('Issued', 'invoice post status'),
23+
'public' => true,
24+
'show_in_admin_all_list' => true,
25+
'show_in_admin_status_list' => true,
26+
'date_floating' => true,
27+
'label_count' => _n_noop(
28+
'Issued <span class="count">(%s)</span>',
29+
'Issued <span class="count">(%s)</span>',
30+
),
31+
],
32+
'invoice_sent' => [
33+
'label' => _x('Sent', 'invoice post status'),
34+
'public' => true,
35+
'show_in_admin_all_list' => true,
36+
'show_in_admin_status_list' => true,
37+
'date_floating' => true,
38+
'label_count' => _n_noop('Sent <span class="count">(%s)</span>', 'Sent <span class="count">(%s)</span>'),
39+
],
40+
'invoice_expired' => [
41+
'label' => _x('Expired', 'invoice post status'),
42+
'public' => true,
43+
'show_in_admin_all_list' => true,
44+
'show_in_admin_status_list' => true,
45+
'date_floating' => true,
46+
'label_count' => _n_noop(
47+
'Expired <span class="count">(%s)</span>',
48+
'Expired <span class="count">(%s)</span>',
49+
),
50+
],
51+
'invoice_paid' => [
52+
'label' => _x('Paid', 'invoice post status'),
53+
'public' => true,
54+
'show_in_admin_all_list' => true,
55+
'show_in_admin_status_list' => true,
56+
'date_floating' => true,
57+
'label_count' => _n_noop('Paid <span class="count">(%s)</span>', 'Paid <span class="count">(%s)</span>'),
58+
],
59+
'invoice_cancelled' => [
60+
'label' => _x('Cancelled', 'invoice post status'),
61+
'public' => true,
62+
'show_in_admin_all_list' => true,
63+
'show_in_admin_status_list' => true,
64+
'date_floating' => true,
65+
'label_count' => _n_noop(
66+
'Cancelled <span class="count">(%s)</span>',
67+
'Cancelled <span class="count">(%s)</span>',
68+
),
69+
],
70+
];
71+
}
72+
}

app/Features/Schema.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Invoice\Features;
4+
5+
trait Schema
6+
{
7+
use Settings;
8+
9+
public function schema($invoice_id, $public = false): array
10+
{
11+
$stored_invoice_series_number = get_field('invoice_series_number', $invoice_id);
12+
$stored_invoice_number = get_field('invoice_number', $invoice_id);
13+
$invoice_number = '';
14+
if ($stored_invoice_series_number) {
15+
$invoice_number = "{$stored_invoice_number}-";
16+
}
17+
$invoice_number .= $stored_invoice_number;
18+
$invoice_number = $stored_invoice_number === 99999 ? null : $invoice_number;
19+
$uuid = get_post_meta($invoice_id, 'uuid', true);
20+
$invoice_view_url = "/invoices/view/{$uuid}";
21+
$invoice_edit_url = "/invoices/edit/{$uuid}";
22+
23+
$private_data = [
24+
'invoice_client' => get_field('invoice_client', $invoice_id, false),
25+
'invoice_client_address' => get_field('invoice_client_address', $invoice_id, false),
26+
'invoice_view_url' => $invoice_view_url,
27+
'invoice_edit_url' => $invoice_edit_url,
28+
'invoice_notes' => get_field('invoice_notes', $invoice_id),
29+
'invoice_terms' => get_field('invoice_terms', $invoice_id),
30+
];
31+
32+
$public_data = [
33+
'ID' => $invoice_id,
34+
'UUID' => $uuid,
35+
'invoice_series_number' => $stored_invoice_series_number,
36+
'invoice_number' => $stored_invoice_number,
37+
'generated_invoice_number' => $invoice_number,
38+
'invoice_issue_date' => get_field(
39+
'invoice_issue_date',
40+
$invoice_id,
41+
false,
42+
),
43+
'invoice_due_date' => get_field(
44+
'invoice_due_date',
45+
$invoice_id,
46+
false,
47+
),
48+
'invoice_sender' => get_field('invoice_sender', $invoice_id, false),
49+
'invoice_sender_address' => get_field('invoice_sender_address', $invoice_id, false),
50+
'invoice_currency' => get_field('invoice_currency', $invoice_id, false),
51+
'invoice_items' => get_field('invoice_items', $invoice_id),
52+
'invoice_status' => get_post_status($invoice_id),
53+
'invoice_tax_amount' => get_field('invoice_tax_amount', $invoice_id),
54+
'invoice_taxes' => get_field('invoice_taxes', $invoice_id),
55+
'invoice_discount_amount' => get_field('invoice_discount_amount', $invoice_id),
56+
'invoice_discounts' => get_field('invoice_discounts', $invoice_id),
57+
'invoice_subtotal' => get_field('invoice_subtotal', $invoice_id),
58+
'invoice_tax_subtotal' => get_field('invoice_tax_subtotal', $invoice_id),
59+
'invoice_taxes_total' => get_field('invoice_taxes_total', $invoice_id),
60+
'invoice_discount_subtotal' => get_field('invoice_discount_subtotal', $invoice_id),
61+
'invoice_discount_total' => get_field('invoice_discount_total', $invoice_id),
62+
'invoice_total' => get_field('invoice_total', $invoice_id),
63+
'invoice_logo' => $this->get_logo($invoice_id),
64+
];
65+
66+
return $public ? $public_data : array_merge($public_data, $private_data);
67+
}
68+
}

app/Features/Settings.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,47 @@
22

33
namespace Invoice\Features;
44

5-
class Settings {
6-
public static function get_logo($invoice_id = null) : ?string {
7-
if($invoice_id) {
5+
trait Settings
6+
{
7+
public function get_logo($invoice_id = null): ?string
8+
{
9+
if ($invoice_id) {
810
$invoice_logo = get_field('invoice_logo', $invoice_id);
9-
if($invoice_logo) {
11+
if ($invoice_logo) {
1012
return $invoice_logo;
1113
}
1214
}
1315
$custom_logo_id = get_theme_mod('custom_logo');
16+
1417
return $custom_logo_id ?
1518
wp_get_attachment_image_src($custom_logo_id, 'full', true)[0] :
1619
null;
1720
}
18-
}
21+
22+
public function get_settings(): array
23+
{
24+
return [
25+
'invoice_last_number' => get_option('invoice_last_number', 0),
26+
'invoice_series' => get_option('invoice_series', []),
27+
'invoice_date_format' => get_option('invoice_date_format', 'd/M/Y'),
28+
'invoice_business_fni_country_code' => get_option('invoice_business_fni_country_code', 'ES'),
29+
'invoice_business_fni' => get_option('invoice_business_fni', ''),
30+
'invoice_business_name' => get_option('invoice_business_name', get_bloginfo()),
31+
'invoice_business_country' => get_option('invoice_business_country', 'ES'),
32+
'invoice_business_state' => get_option('invoice_business_state', ''),
33+
'invoice_business_address' => get_option('invoice_business_address', ''),
34+
'invoice_business_address_cont' => get_option('invoice_business_address_cont', ''),
35+
'invoice_business_city' => get_option('invoice_business_city', ''),
36+
'invoice_business_postal_code' => get_option('invoice_business_postal_code', ''),
37+
'invoices_taxes' => get_option('invoice_taxes', []),
38+
'invoice_discounts' => get_option('invoice_discounts', []),
39+
'invoice_currency' => get_option('invoice_currency', 'EUR'),
40+
'invoice_currency_symbol' => get_option('invoice_currency_symbol', '&euro;'),
41+
'invoice_logo' => $this->get_logo(),
42+
'spain_iva' => get_option('spain_iva'),
43+
'spain_irpf' => get_option('spain_irpf'),
44+
'selected_invoice_tax' => get_option('selected_invoice_tax', 21),
45+
'selected_invoice_discount' => get_option('selected_invoice_discount'),
46+
];
47+
}
48+
}

app/Hooks/Blocks.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,22 @@
22

33
namespace Invoice\Hooks;
44

5-
class Blocks {
6-
public static function init() : void {
7-
add_action('init', self::register_block_types(...));
8-
}
5+
class Blocks
6+
{
7+
public function init(): void
8+
{
9+
add_action('init', [$this, 'register_block_types']);
10+
}
911

10-
public static function register_block_types(): void
12+
public function register_block_types(): void
1113
{
1214
$block_types = glob(APP_INVOICE_DIR . '/blocks/*');
1315
if (count($block_types) > 0) {
1416
foreach ($block_types as $block) {
1517
if (is_dir($block)) {
16-
$block_data = register_block_type($block);
17-
18-
add_filter(
19-
'allowed_block_types_all',
20-
function ($allowed_blocks) use ($block_data) {
21-
if (!is_array($allowed_blocks)) return $allowed_blocks;
22-
$allowed_blocks[] = $block_data->name;
23-
return $allowed_blocks;
24-
}, 99, 2);
18+
register_block_type($block);
2519
}
2620
}
2721
}
2822
}
29-
}
23+
}

app/Hooks/Gutenberg.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
namespace Invoice\Hooks;
44

5-
class Gutenberg {
6-
public static function init() : void {
7-
add_filter('block_categories_all', self::block_categories_all(...), 10, 2);
8-
}
5+
class Gutenberg
6+
{
7+
public function init(): void
8+
{
9+
add_filter('block_categories_all', [$this, 'block_categories_all'], 10, 2);
10+
}
911

10-
public static function block_categories_all(array $categories, $post) : array {
11-
return array_merge(
12-
$categories,
13-
array (
14-
array(
15-
'slug' => 'invoice',
16-
'title' => __( 'Invoice' ),
17-
),
18-
),
19-
);
20-
}
21-
}
12+
public function block_categories_all(array $categories, $post): array
13+
{
14+
return array_merge(
15+
$categories,
16+
[
17+
[
18+
'slug' => 'invoice',
19+
'title' => __('Invoice'),
20+
],
21+
],
22+
);
23+
}
24+
}

0 commit comments

Comments
 (0)