78% payhere-payment-gateway

Code Review | PayHere Payment Gateway

WordPress plugin PayHere Payment Gateway scored78%from 54 tests.

About plugin

  • Plugin page: payhere-payment-g...
  • Plugin version: 2.2.12
  • PHP version: 7.4.16
  • WordPress compatibility: 3.0.1-6.2.2
  • WordPress version: 6.3.1
  • First release: Jul 14, 2016
  • Latest release: Nov 30, 2023
  • Number of updates: 61
  • Update frequency: every 44.2 days
  • Top authors: payhere (100%)

Code review

54 tests

User reviews

5 reviews

Install metrics

2,000+ active /33,874 total downloads

Benchmarks

Plugin footprint 83% from 16 tests

Installer Passed 1 test

🔺 Critical test (weight: 50) | The install procedure must perform silently
Installer ran successfully

Server metrics [RAM: ▲0.19MB] [CPU: ▼0.47ms] Passed 4 tests

This is a short check of server-side resources used by PayHere Payment Gateway
No issues were detected with server-side resource usage
PageMemory (MB)CPU Time (ms)
Home /3.64 ▲0.1739.55 ▼3.91
Dashboard /wp-admin3.54 ▲0.2358.45 ▲8.92
Posts /wp-admin/edit.php3.59 ▲0.2351.47 ▲5.78
Add New Post /wp-admin/post-new.php6.08 ▲0.1993.48 ▼6.33
Media Library /wp-admin/upload.php3.40 ▲0.1736.91 ▲2.59
Cards on File /wp-admin/admin.php?page=payhere_list_customer_list3.3733.78

Server storage [IO: ▲0.23MB] [DB: ▲0.00MB] Passed 3 tests

Analyzing filesystem and database footprints of this plugin
There were no storage issued detected upon installing this plugin
Filesystem: 46 new files
Database: no new tables, 7 new options
New WordPress options
widget_recent-comments
can_compress_scripts
payhere_db_version
widget_recent-posts
theysaidso_admin_options
db_upgraded
widget_theysaidso_widget

Browser metrics Passed 4 tests

PayHere Payment Gateway: an overview of browser usage
Normal browser usage
PageNodesMemory (MB)Script (ms)Layout (ms)
Home /2,809 ▲4714.35 ▲0.011.72 ▲0.0740.20 ▼6.93
Dashboard /wp-admin2,213 ▲395.62 ▼0.0290.79 ▼9.7444.18 ▲2.22
Posts /wp-admin/edit.php2,115 ▲152.01 ▲0.0840.83 ▼1.6736.66 ▼0.25
Add New Post /wp-admin/post-new.php1,536 ▲1023.83 ▲0.60638.18 ▲3.8354.90 ▲3.92
Media Library /wp-admin/upload.php1,418 ▲184.16 ▼0.0495.65 ▲1.0743.26 ▲2.44
Cards on File /wp-admin/admin.php?page=payhere_list_customer_list1,0991.7828.6829.64

Uninstaller [IO: ▲0.00MB] [DB: ▲0.00MB] 75% from 4 tests

🔸 Tests weight: 35 | Verifying that this plugin uninstalls completely without leaving any traces
It is recommended to fix the following
  • The uninstall procedure has failed, leaving 7 options in the database
    • widget_recent-comments
    • payhere_db_version
    • can_compress_scripts
    • widget_recent-posts
    • widget_theysaidso_widget
    • theysaidso_admin_options
    • db_upgraded

Smoke tests 50% from 4 tests

Server-side errors Passed 1 test

🔹 Test weight: 20 | This is a shallow check for server-side errors
Even though no errors were found, this is by no means an exhaustive test

SRP 0% from 2 tests

🔹 Tests weight: 20 | The single-responsibility principle: PHP files have to remain inert when accessed directly, throwing no errors and performing no actions
The following issues need your attention
  • 1× GET requests to PHP files return non-empty strings:
    • > /wp-content/plugins/payhere-payment-gateway/public/partials/payhere-ipg-public-display.php
  • 12× PHP files trigger server-side errors or warnings when accessed directly (only 10 are shown):
    • > PHP Fatal error
      Uncaught Error: Call to undefined function esc_url() in wp-content/plugins/payhere-payment-gateway/public/partials/checkout-form-sale.php:14
    • > PHP Warning
      require_once(ABSPATHwp-admin/includes/screen.php): failed to open stream: No such file or directory in wp-content/plugins/payhere-payment-gateway/includes/class-phcustomerslist.php on line 13
    • > PHP Fatal error
      Uncaught Error: Call to undefined function esc_url() in wp-content/plugins/payhere-payment-gateway/public/partials/checkout-form-auth.php:14
    • > PHP Notice
      Undefined variable: onsite_checkout_enabled in wp-content/plugins/payhere-payment-gateway/public/partials/checkout-form-auth.php on line 12
    • > PHP Fatal error
      Uncaught Error: Class 'PayHereToken' not found in wp-content/plugins/payhere-payment-gateway/gateway/class-payherecapturepayment.php:19
    • > PHP Fatal error
      Uncaught Error: Class 'WC_Payment_Gateway' not found in wp-content/plugins/payhere-payment-gateway/gateway/class-wcgatewaypayhere.php:20
    • > PHP Fatal error
      require_once(): Failed opening required 'ABSPATHwp-admin/includes/screen.php' (include_path='.:/usr/share/php') in wp-content/plugins/payhere-payment-gateway/includes/class-phcustomerslist.php on line 13
    • > PHP Fatal error
      Uncaught Error: Class 'PayHereToken' not found in wp-content/plugins/payhere-payment-gateway/gateway/class-chargepayment.php:22
    • > PHP Fatal error
      Uncaught Error: Call to undefined function get_the_ID() in wp-content/plugins/payhere-payment-gateway/admin/partials/order-auth-payment.php:13
    • > PHP Notice
      Undefined variable: onsite_checkout_enabled in wp-content/plugins/payhere-payment-gateway/public/partials/checkout-form-sale.php on line 12

User-side errors Passed 1 test

🔹 Test weight: 20 | This is a shallow check for browser errors
There were no browser issues found

Optimizations

Plugin configuration 90% from 29 tests

readme.txt 94% from 16 tests

You should put a lot of thought into formatting readme.txt as it is used by WordPress.org to prepare the public listing of your plugin
These attributes need to be fixed:
  • Plugin Name: Please specify the plugin name on the first line ( === payhere-payment-gateway === )
The official readme.txt is a good inspiration

payhere-payment-gateway/payhere-payment-gateway.php 85% from 13 tests

"PayHere Payment Gateway" version 2.2.12's primary PHP file adds more information about the plugin and serves as the entry point for WordPress
Please make the necessary changes and fix the following:
  • Description: Please keep the plugin description shorter than 140 characters (currently 149 characters long)
  • Text Domain: If you choose to specify the text domain, it must be the same as the plugin slug; optional since WordPress version 4.6

Code Analysis Passed 3 tests

File types Passed 1 test

🔸 Test weight: 35 | Executable files are considered dangerous and should not be included with any WordPress plugin
Everything looks great! No dangerous files found in this plugin2,292 lines of code in 35 files:
LanguageFilesBlank linesComment linesLines of code
PHP254601,3711,902
CSS3358203
JavaScript62981185
SVG1002

PHP code Passed 2 tests

This is a very shot review of cyclomatic complexity and code structure
Although this was not an exhaustive test, there were no cyclomatic complexity issues detected
Cyclomatic complexity
Average complexity per logical line of code0.27
Average class complexity11.81
▷ Minimum class complexity1.00
▷ Maximum class complexity89.00
Average method complexity2.65
▷ Minimum method complexity1.00
▷ Maximum method complexity25.00
Code structure
Namespaces0
Interfaces0
Traits0
Classes16
▷ Abstract classes00.00%
▷ Concrete classes16100.00%
▷ Final classes00.00%
Methods103
▷ Static methods65.83%
▷ Public methods9087.38%
▷ Protected methods10.97%
▷ Private methods1211.65%
Functions5
▷ Named functions480.00%
▷ Anonymous functions120.00%
Constants13
▷ Global constants17.69%
▷ Class constants1292.31%
▷ Public constants12100.00%

Plugin size Passed 2 tests

Image compression Passed 2 tests

Often times overlooked, PNG files can occupy unnecessary space in your plugin
4 PNG files occupy 0.08MB with 0.03MB in potential savings
Potential savings
Compression of 4 random PNG files using pngquant
FileSize - originalSize - compressedSavings
public/images/helapay.png61.35KB29.54KB▼ 51.85%
public/images/master.png7.02KB2.59KB▼ 63.06%
admin/images/cards.png7.33KB7.12KB▼ 2.75%
public/images/visa.png5.22KB2.36KB▼ 54.81%