Skip to content

Commit

Permalink
phpcs configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
BeycanDeveloper committed Jan 25, 2024
1 parent 50a6d32 commit e193b89
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
34 changes: 34 additions & 0 deletions .github/workflows/phpcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PHPCS Check

on:
push:
branches:
- master

jobs:
phpcs:
name: PHPCS Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Install PHPCS
run: |
composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev squizlabs/php_codesniffer=* slevomat/coding-standard
- name: Run PHPCS
run: |
composer phpcs --standard=phpcs.xml .
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "PHPCS check failed. Please fix the issues before merging."
exit 1
fi
38 changes: 23 additions & 15 deletions app/DonateBox/DonateBox.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Donation\DonateBox;

use \BeycanPress\CryptoPay\Services;
use \BeycanPress\CryptoPay\Donation\Lang;
use \BeycanPress\CryptoPay\PluginHero\Hook;
use \BeycanPress\CryptoPay\PluginHero\Helpers;
use BeycanPress\CryptoPay\Services;
use BeycanPress\CryptoPay\Donation\Lang;
use BeycanPress\CryptoPay\PluginHero\Hook;
use BeycanPress\CryptoPay\PluginHero\Helpers;

class DonateBox
{
Expand All @@ -14,31 +16,37 @@ class DonateBox
/**
* @var string
*/
private $receiver;
private string $receiver;

/**
* @return void
*/
public function __construct()
{
add_action('init', function() {
add_action('init', function (): void {
add_shortcode('cryptopay-donation-box', array($this, 'init'));
});
}

public function init()
/**
* @return string
*/
public function init(): string
{
Hook::addFilter('lang', function($lang) {
Hook::addFilter('lang', function ($lang) {
return array_merge($lang, Lang::get());
});

$this->addons->donation->addScript('main.js');
$this->addons->donation->addStyle('main.css');
Helpers::getAddon('donation')->addScript('main.js');
Helpers::getAddon('donation')->addStyle('main.css');

$cryptopay = Services::preparePaymentProcess('donation', false);

return $this->addons->donation->view('donate-box', [
'currency' => $this->setting('donationCurrency'),
'amounts' => $this->setting('donationDonateAmounts'),
'theme' => $this->setting('theme'),
return Helpers::getAddon('donation')->view('donate-box', [
'currency' => Helpers::getSetting('donationCurrency'),
'amounts' => Helpers::getSetting('donationDonateAmounts'),
'theme' => Helpers::getSetting('theme'),
'cryptopay' => $cryptopay,
]);
}
}
}
61 changes: 44 additions & 17 deletions app/DonateBox/DonateBoxWidget.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Donation\DonateBox;

use \BeycanPress\CryptoPay\PluginHero\Helpers;
use BeycanPress\CryptoPay\Helpers;

class DonateBoxWidget extends \WP_Widget
{
use Helpers;

function __construct()
/**
* Constructor
*/
public function __construct()
{
parent::__construct(
__CLASS__,
esc_html__('# CryptoPay Donation Box', 'cryptopay'),
__CLASS__,
esc_html__('# CryptoPay Donation Box', 'cryptopay'),
[
// @phpcs:ignore
'description' => esc_html__('With this widget you can add a box to your site to receive donations with cryptocurrencies.', 'cryptopay')
]
]
);
}

public function widget($args, $instance)

/**
* Widget
*
* @param array<string,string> $args
* @param array<string,string> $instance
* @return void
*/
// @phpcs:ignore
public function widget($args, $instance): void
{
$title = apply_filters('widget_title', $instance['title']);

print($args['before_widget']);

$title = !empty($title) ? $title : esc_html__('CryptoPay Donation Box', 'cryptopay');

print($args['before_title'] . $title . $args['after_title']);
Expand All @@ -33,17 +45,32 @@ public function widget($args, $instance)

print($args['after_widget']);
}

public function form($instance)

/**
* Form
*
* @param array<string,string> $instance
* @return void
*/
// @phpcs:ignore
public function form($instance)
{
$title = isset($instance['title']) ? $instance['title'] : null;
$this->viewEcho('widget-form', compact('title'));
Helpers::getAddon('donation')->viewEcho('widget-form', compact('title'));
}


/**
* Update
*
* @param array<string,string> $newInstance
* @param array<string,string> $oldInstance
* @return array<string,string>
*/
// @phpcs:ignore
public function update($newInstance, $oldInstance)
{
$instance = [];
$instance['title'] = !empty($newInstance['title']) ? sanitize_text_field($newInstance['title']) : null;
return $instance;
}
}
}
}
44 changes: 27 additions & 17 deletions app/Integrations.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,60 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Donation;

use BeycanPress\CryptoPay\PluginHero\Helpers;
use BeycanPress\CryptoPay\Helpers;

class Integrations
{
use Helpers;

/**
* Constructor
*/
public function __construct()
{
// Register widget
add_action('widgets_init', function() {
add_action('widgets_init', function (): void {
register_widget(DonateBox\DonateBoxWidget::class);
});

if (is_admin()) {
// Register Gutenberg block
add_action('enqueue_block_editor_assets', function() {
add_action('enqueue_block_editor_assets', function (): void {
global $pagenow;
$dependencies = $pagenow === 'widgets.php' ? ['wp-edit-widgets'] : ['wp-editor'];

$this->addons->donation->addScript('gutenberg.js', array_merge($dependencies, ['jquery', 'wp-element', 'wp-blocks']));
});
Helpers::getAddon('donation')->addScript(
'gutenberg.js',
array_merge($dependencies, ['jquery', 'wp-element', 'wp-blocks'])
);
});

// Register TinyMCE button
add_action('admin_head', function() {
add_filter('mce_external_plugins', function($pluginArray) {
add_action('admin_head', function (): void {
add_filter('mce_external_plugins', function ($pluginArray) {
// @phpcs:ignore
$pluginArray['beycanpress/cryptopay-donation-box'] = plugin_dir_url('cryptopay-donation/index.php') . 'assets/js/tinymce.js';
return $pluginArray;
});
add_filter('mce_buttons', function($buttons) {
add_filter('mce_buttons', function ($buttons) {
array_push($buttons, 'beycanpress/cryptopay-donation-box');
return $buttons;
});
});
} else {
add_filter('the_content', function($content) {

add_filter('the_content', function ($content) {
if (function_exists('WC')) {
if (is_checkout() || is_account_page() || is_woocommerce() || is_cart()) return $content;
}
if (is_checkout() || is_account_page() || is_woocommerce() || is_cart()) {
return $content;
}
}

if (is_page() || is_single()) {
$showIn = is_page() ? $this->setting('donationShowInPages') : $this->setting('donationShowInPosts');

$showIn = is_page() ?
Helpers::getSetting('donationShowInPages') :
Helpers::getSetting('donationShowInPosts');

if ($showIn == 'show-in-begin') {
$content = do_shortcode('[cryptopay-donation-box]') . $content;
} elseif ($showIn == 'show-in-end') {
Expand All @@ -56,4 +66,4 @@ public function __construct()
});
}
}
}
}
10 changes: 7 additions & 3 deletions app/Lang.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Donation;

class Lang
{
public static function get() : array
/**
* @return array<string,string>
*/
public static function get(): array
{
return [
"orderAmount" => esc_html__('Donate amount', 'cryptopay'),
Expand All @@ -19,5 +24,4 @@ public static function get() : array
"paymentTimedOut" => esc_html__('Donation timed out!', 'cryptopay'),
];
}

}
}
22 changes: 12 additions & 10 deletions app/Loader.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Donation;

use BeycanPress\CryptoPay\Helpers;
use BeycanPress\CryptoPay\PluginHero\Hook;
use BeycanPress\CryptoPay\PluginHero\Helpers;
use BeycanPress\CryptoPay\PluginHero\Updater;
use BeycanPress\CryptoPay\Pages\TransactionPage;

class Loader
{
use Helpers;

/**
* @return void
*/
public function __construct()
{
new Updater([
'requires' => '5.0',
'requires_php' => '7.4',
'plugin_file' => 'cryptopay-donation/index.php',
'plugin_version' => $this->addons->donation->getVersion(),
'requires_php' => '8.1',
'plugin_file' => 'cryptopay-donation/cryptopay-donation.php',
'plugin_version' => Helpers::getAddon('donation')->getVersion(),
'icons' => [
'2x' => plugin_dir_url(dirname(__FILE__, 2) . '/index.php') . '/assets/images/icon-256x256.png',
'1x' => plugin_dir_url(dirname(__FILE__, 2) . '/index.php') . '/assets/images/icon-128x128.png',
]
]);

Hook::addFilter('apply_discount_donation', '__return_false');
Hook::addFilter('models', function($models) {
Hook::addFilter('models', function ($models) {
return array_merge($models, [
'donation' => new Models\DonationTransaction()
]);
});

Hook::addFilter('transaction_status_donation', fn() => 'completed');

if (is_admin()) {
new TransactionPage(
esc_html__('Donation transactions', 'cryptopay'),
'donation',
3,
[],
false,
['orderId', 'status', 'updatedAt']
);
} else {
new DonateBox\DonateBox();
}

new Integrations();
}
}
13 changes: 9 additions & 4 deletions app/Models/DonationTransaction.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Donation\Models;

use BeycanPress\CryptoPay\Models\AbstractTransaction;

class DonationTransaction extends AbstractTransaction
class DonationTransaction extends AbstractTransaction
{
public $addon = 'donation';

public string $addon = 'donation';

/**
* Constructor
*/
public function __construct()
{
parent::__construct('donation_transaction');
}
}
}
Loading

0 comments on commit e193b89

Please sign in to comment.