diff --git a/.gitignore b/.gitignore index e47b16f64..faedb49da 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ src/assets/css/tainacan-admin.css.map cypress/videos cypress/screenshots .vscode -src/pdf-viewer/pdfjs-dist \ No newline at end of file +src/pdf-viewer/pdfjs-dist +report.txt \ No newline at end of file diff --git a/composer.json b/composer.json index 524f7f3e8..ae246dec5 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,17 @@ "require": { "respect/validation": "^1.1" }, + "require-dev": { + "squizlabs/php_codesniffer": "^2.2 || ^3.0.2", + "wimg/php-compatibility": "*" + }, + "prefer-stable" : true, "minimum-stability": "dev", "config": { "vendor-dir": "src/vendor" + }, + "scripts": { + "post-install-cmd": "\"src/vendor/bin/phpcs\" --config-set installed_paths src/vendor/wimg/php-compatibility", + "post-update-cmd" : "\"src/vendor/bin/phpcs\" --config-set installed_paths src/vendor/wimg/php-compatibility" } } diff --git a/composer.lock b/composer.lock index 76bfecf3f..353e12067 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "64fbb4d01225b482970da995b00dccfb", + "content-hash": "b5a7a81dd7eed9bc122ee36e472c6430", "packages": [ { "name": "respect/validation", @@ -131,11 +131,115 @@ "time": "2017-10-11T12:05:26+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "3.2.3", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2018-02-20T21:35:23+00:00" + }, + { + "name": "wimg/php-compatibility", + "version": "8.1.0", + "source": { + "type": "git", + "url": "https://github.com/wimg/PHPCompatibility.git", + "reference": "4ac01e4fe8faaa4f8d3b3cd06ea92e5418ce472e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wimg/PHPCompatibility/zipball/4ac01e4fe8faaa4f8d3b3cd06ea92e5418ce472e", + "reference": "4ac01e4fe8faaa4f8d3b3cd06ea92e5418ce472e", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.2 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "PHPCompatibility\\": "PHPCompatibility/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "time": "2017-12-27T21:58:38+00:00" + } + ], "aliases": [], "minimum-stability": "dev", "stability-flags": [], - "prefer-stable": false, + "prefer-stable": true, "prefer-lowest": false, "platform": [], "platform-dev": [] diff --git a/docs/class-reference-filters.md b/docs/class-reference-filters.md index 04a897dbc..920f55729 100644 --- a/docs/class-reference-filters.md +++ b/docs/class-reference-filters.md @@ -108,7 +108,7 @@ Represents the entity Filter ### `protected $repository = 'Filters'` {@inheritDoc} -### `public function __toArray()` +### `public function _toArray()` **Returns:** array diff --git a/src/api/class-tainacan-rest-controller.php b/src/api/class-tainacan-rest-controller.php index cde5f890f..dda6d2037 100644 --- a/src/api/class-tainacan-rest-controller.php +++ b/src/api/class-tainacan-rest-controller.php @@ -29,7 +29,7 @@ class REST_Controller extends \WP_REST_Controller { $get_ = 'get_' . $attribute; $object_filtered[ $attribute ] = $object->$get_(); } - } catch ( \Error $error ) { + } catch ( \Exception $error ) { // Do nothing } } @@ -37,7 +37,7 @@ class REST_Controller extends \WP_REST_Controller { try{ $get_ = 'get_' . $attributes; $object_filtered[$attributes] = $object->$get_(); - } catch (\Error $error){ + } catch (\Exception $error){ // Do nothing } } @@ -57,7 +57,7 @@ class REST_Controller extends \WP_REST_Controller { try { $set_ = 'set_' . $key; $object->$set_( $value ); - } catch (\Error $error){ + } catch (\Exception $error){ // Do nothing } } diff --git a/src/api/endpoints/class-tainacan-rest-collections-controller.php b/src/api/endpoints/class-tainacan-rest-collections-controller.php index bc39d3531..94225a244 100644 --- a/src/api/endpoints/class-tainacan-rest-collections-controller.php +++ b/src/api/endpoints/class-tainacan-rest-collections-controller.php @@ -145,7 +145,7 @@ class REST_Collections_Controller extends REST_Controller { if(!isset($request['fetch_only'])) { - $item_arr = $item->__toArray(); + $item_arr = $item->_toArray(); if ( $request['context'] === 'edit' ) { $moderators_ids = $item_arr['moderators_ids']; @@ -239,7 +239,7 @@ class REST_Collections_Controller extends REST_Controller { try { $prepared_post = $this->prepare_item_for_database( $body ); - } catch (\Error $exception){ + } catch (\Exception $exception){ return new \WP_REST_Response($exception->getMessage(), 400); } diff --git a/src/api/endpoints/class-tainacan-rest-export-controller.php b/src/api/endpoints/class-tainacan-rest-export-controller.php index 6d18844d5..ecfe7cacc 100644 --- a/src/api/endpoints/class-tainacan-rest-export-controller.php +++ b/src/api/endpoints/class-tainacan-rest-export-controller.php @@ -137,7 +137,7 @@ class REST_Export_Controller extends REST_Controller { $prepared_item = []; foreach ($items_metadata as $item_metadata){ - $prepared_item[] = $item_metadata->__toArray(); + $prepared_item[] = $item_metadata->_toArray(); } return $prepared_item; diff --git a/src/api/endpoints/class-tainacan-rest-field-types-controller.php b/src/api/endpoints/class-tainacan-rest-field-types-controller.php index 9e8b9371a..f685757f4 100644 --- a/src/api/endpoints/class-tainacan-rest-field-types-controller.php +++ b/src/api/endpoints/class-tainacan-rest-field-types-controller.php @@ -70,7 +70,7 @@ class REST_Field_Types_Controller extends REST_Controller { $name = "\Tainacan\Field_Types\\$item"; $field_type = new $name(); - $field_arr = $field_type->__toArray(); + $field_arr = $field_type->_toArray(); $field_arr['name'] = $item; return $field_arr; diff --git a/src/api/endpoints/class-tainacan-rest-fields-controller.php b/src/api/endpoints/class-tainacan-rest-fields-controller.php index da6849023..e6de3807c 100644 --- a/src/api/endpoints/class-tainacan-rest-fields-controller.php +++ b/src/api/endpoints/class-tainacan-rest-fields-controller.php @@ -197,7 +197,7 @@ class REST_Fields_Controller extends REST_Controller { try { $prepared = $this->prepare_item_for_database( $request->get_body(), $collection_id ); - } catch (\Error $exception){ + } catch (\Exception $exception){ return new \WP_REST_Response($exception->getMessage(), 400); } @@ -217,7 +217,7 @@ class REST_Fields_Controller extends REST_Controller { } elseif (!empty($request->get_body())) { try { $prepared = $this->prepare_item_for_database( $request->get_body() ); - } catch ( \Error $exception ) { + } catch ( \Exception $exception ) { return new \WP_REST_Response( $exception->getMessage(), 400 ); } @@ -266,9 +266,9 @@ class REST_Fields_Controller extends REST_Controller { */ public function prepare_item_for_response( $item, $request ) { if(!empty($item)){ - $item_arr = $item->__toArray(); + $item_arr = $item->_toArray(); - $item_arr['field_type_object'] = $item->get_field_type_object()->__toArray(); + $item_arr['field_type_object'] = $item->get_field_type_object()->_toArray(); if($request['context'] === 'edit'){ $item_arr['current_user_can_edit'] = $item->can_edit(); diff --git a/src/api/endpoints/class-tainacan-rest-filter-types-controller.php b/src/api/endpoints/class-tainacan-rest-filter-types-controller.php index c418fd856..aa02f2172 100644 --- a/src/api/endpoints/class-tainacan-rest-filter-types-controller.php +++ b/src/api/endpoints/class-tainacan-rest-filter-types-controller.php @@ -55,7 +55,7 @@ class REST_Filter_Types_Controller extends REST_Controller { $name = "\Tainacan\Filter_Types\\$item"; $filter_type = new $name(); - $filter_arr = $filter_type->__toArray(); + $filter_arr = $filter_type->_toArray(); $filter_arr['name'] = $item; return $filter_arr; diff --git a/src/api/endpoints/class-tainacan-rest-filters-controller.php b/src/api/endpoints/class-tainacan-rest-filters-controller.php index b844f3951..c4cf8b2fc 100644 --- a/src/api/endpoints/class-tainacan-rest-filters-controller.php +++ b/src/api/endpoints/class-tainacan-rest-filters-controller.php @@ -131,7 +131,7 @@ class REST_Filters_Controller extends REST_Controller { try { $set_ = 'set_'. $attribute; $filter_obj->$set_($value); - } catch (\Error $error){ + } catch (\Exception $error){ // } } @@ -315,11 +315,11 @@ class REST_Filters_Controller extends REST_Controller { */ public function prepare_item_for_response( $item, $request ) { if(!empty($item)) { - $item_arr = $item->__toArray(); + $item_arr = $item->_toArray(); if($request['context'] === 'edit'){ $item_arr['current_user_can_edit'] = $item->can_edit(); - $item_arr['filter_type_object'] = $item->get_filter_type_object()->__toArray(); + $item_arr['filter_type_object'] = $item->get_filter_type_object()->_toArray(); $item_arr['enabled'] = $item->get_enabled_for_collection(); } diff --git a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php index 2ea202c94..d2c394df0 100644 --- a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php +++ b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php @@ -96,7 +96,7 @@ class REST_Item_Metadata_Controller extends REST_Controller { * @return array|\WP_Error|\WP_REST_Response */ public function prepare_item_for_response( $item, $request ) { - $item_arr = $item->__toArray(); + $item_arr = $item->_toArray(); if($request['context'] === 'edit'){ $item_arr['current_user_can_edit'] = $item->can_edit(); @@ -209,7 +209,7 @@ class REST_Item_Metadata_Controller extends REST_Controller { } elseif($field->get_accept_suggestion()) { $log = $this->item_metadata_repository->suggest( $item_metadata ); - $prepared_item = $log->__toArray(); + $prepared_item = $log->_toArray(); } else { return new \WP_REST_Response( [ diff --git a/src/api/endpoints/class-tainacan-rest-items-controller.php b/src/api/endpoints/class-tainacan-rest-items-controller.php index 4286ec3ea..206d75608 100644 --- a/src/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/api/endpoints/class-tainacan-rest-items-controller.php @@ -92,6 +92,8 @@ class REST_Items_Controller extends REST_Controller { * @param $item_object * @param $item_array * + * @param array $args + * * @return mixed */ private function add_metadata_to_item($item_object, $item_array, $args = []){ @@ -100,7 +102,7 @@ class REST_Items_Controller extends REST_Controller { foreach($item_metadata as $index => $me){ $field = $me->get_field(); $slug = $field->get_slug(); - $item_metadata_array = $me->__toArray(); + $item_metadata_array = $me->_toArray(); $item_array['metadata'][ $slug ]['name'] = $field->get_name(); $item_array['metadata'][ $slug ]['value'] = $item_metadata_array['value']; @@ -125,7 +127,7 @@ class REST_Items_Controller extends REST_Controller { if(!empty($item)){ if(!isset($request['fetch_only'])) { - $item_arr = $item->__toArray(); + $item_arr = $item->_toArray(); if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); @@ -298,7 +300,7 @@ class REST_Items_Controller extends REST_Controller { try { $this->prepare_item_for_database( [ $item, $collection_id ] ); - } catch (\Error $exception){ + } catch (\Exception $exception){ return new \WP_REST_Response($exception->getMessage(), 400); } diff --git a/src/api/endpoints/class-tainacan-rest-logs-controller.php b/src/api/endpoints/class-tainacan-rest-logs-controller.php index 013019b67..8324dcc72 100644 --- a/src/api/endpoints/class-tainacan-rest-logs-controller.php +++ b/src/api/endpoints/class-tainacan-rest-logs-controller.php @@ -77,7 +77,7 @@ class REST_Logs_Controller extends REST_Controller { if(!empty($item)){ if(!isset($request['fetch_only'])) { - $item_array = $item->__toArray(); + $item_array = $item->_toArray(); unset($item_array['value']); unset($item_array['old_value']); diff --git a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php index 1a7dc569a..4d603d16d 100644 --- a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php +++ b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php @@ -95,7 +95,7 @@ class REST_Taxonomies_Controller extends REST_Controller { public function prepare_item_for_response( $item, $request ) { if(!empty($item)) { if(!isset($request['fetch_only'])) { - $item_arr = $item->__toArray(); + $item_arr = $item->_toArray(); if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); diff --git a/src/api/endpoints/class-tainacan-rest-terms-controller.php b/src/api/endpoints/class-tainacan-rest-terms-controller.php index 80e206984..8f90da645 100644 --- a/src/api/endpoints/class-tainacan-rest-terms-controller.php +++ b/src/api/endpoints/class-tainacan-rest-terms-controller.php @@ -90,7 +90,7 @@ class REST_Terms_Controller extends REST_Controller { try { $this->term->$set_( $value ); - } catch (\Error $error){ + } catch (\Exception $error){ // Do nothing } } @@ -262,7 +262,7 @@ class REST_Terms_Controller extends REST_Controller { public function prepare_item_for_response( $item, $request ) { if(!empty($item)){ if(!isset($request['fetch_only'])) { - $item_arr = $item->__toArray(); + $item_arr = $item->_toArray(); if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); diff --git a/src/classes/class-tainacan-embed.php b/src/classes/class-tainacan-embed.php index 3950fec44..b6312d91c 100644 --- a/src/classes/class-tainacan-embed.php +++ b/src/classes/class-tainacan-embed.php @@ -18,14 +18,14 @@ class Embed { /** * Replace default WordPress embedders with HTML 5 tags instead of shortcodes */ - add_filter('wp_embed_handler_video', [&$this, 'filter_video_embed'], 10, 4); - add_filter('wp_embed_handler_audio', [&$this, 'filter_audio_embed'], 10, 4); + add_filter('wp_embed_handler_video', [$this, 'filter_video_embed'], 10, 4); + add_filter('wp_embed_handler_audio', [$this, 'filter_audio_embed'], 10, 4); /** * ADD PDF Embed handler using PDF.js * @var [type] */ - wp_embed_register_handler( 'pdf', '#^https?://.+?\.(pdf)$#i', [&$this, 'pdf_embed_handler'] ); + wp_embed_register_handler( 'pdf', '#^https?://.+?\.(pdf)$#i', [$this, 'pdf_embed_handler'] ); } diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index 576408d62..986607c00 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -65,8 +65,8 @@ class Collection extends Entity { return 'Hello, my name is ' . $this->get_name(); } - public function __toArray() { - $array_collection = parent::__toArray(); + public function _toArray() { + $array_collection = parent::_toArray(); $array_collection['thumbnail'] = $this->get_thumbnail(); $array_collection['header_image'] = $this->get_header_image(); diff --git a/src/classes/entities/class-tainacan-entity.php b/src/classes/entities/class-tainacan-entity.php index 86cbfdfad..3f8391224 100644 --- a/src/classes/entities/class-tainacan-entity.php +++ b/src/classes/entities/class-tainacan-entity.php @@ -333,7 +333,7 @@ class Entity { return true; } - public function __toArray(){ + public function _toArray(){ $repository = $this->get_repository(); $map = $repository->get_map(); @@ -345,8 +345,8 @@ class Entity { return $attributes; } - public function __toJSON(){ - return json_encode($this->__toArray(), JSON_NUMERIC_CHECK); + public function _toJson(){ + return json_encode($this->_toArray(), JSON_NUMERIC_CHECK); } /** diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php index 17890ca79..2a5adca48 100644 --- a/src/classes/entities/class-tainacan-filter.php +++ b/src/classes/entities/class-tainacan-filter.php @@ -37,8 +37,8 @@ class Filter extends Entity { * @return array * @throws \Exception */ - public function __toArray(){ - $filter_array = parent::__toArray(); + public function _toArray(){ + $filter_array = parent::_toArray(); $field_id = $filter_array['field']; $filter_array['field'] = []; diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index 092b25d90..e1f90e0c9 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -111,7 +111,7 @@ class Item_Metadata_Entity extends Entity { foreach ($value as $v) { if ( $v instanceof Term || $v instanceof ItemMetadataEntity ) { - $return[] = $v->__toArray(); + $return[] = $v->_toArray(); } else { $return[] = $v; } @@ -122,7 +122,7 @@ class Item_Metadata_Entity extends Entity { $return = ''; if ( $value instanceof Term || $value instanceof ItemMetadataEntity ) { - $return = $value->__toArray(); + $return = $value->_toArray(); } else { $return = $value; } @@ -136,7 +136,7 @@ class Item_Metadata_Entity extends Entity { * Convert the object to an Array * @return array the representation of this object as an array */ - public function __toArray(){ + public function _toArray(){ $as_array = []; $as_array['value'] = $this->get_value_as_array(); @@ -147,8 +147,8 @@ class Item_Metadata_Entity extends Entity { $as_array['date_i18n'] = $this->get_date_i18n($this->get_value_as_string()); } - $as_array['item'] = $this->get_item()->__toArray(); - $as_array['field'] = $this->get_field()->__toArray(); + $as_array['item'] = $this->get_item()->_toArray(); + $as_array['field'] = $this->get_field()->_toArray(); return $as_array; } diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index a7ca5c8e1..6a7e566c3 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -49,8 +49,8 @@ class Item extends Entity { return 'Hello, my name is ' . $this->get_title(); } - public function __toArray() { - $array_item = parent::__toArray(); + public function _toArray() { + $array_item = parent::_toArray(); $array_item['thumbnail'] = $this->get_thumbnail(); $array_item['_thumbnail_id'] = $this->get__thumbnail_id(); @@ -417,7 +417,7 @@ class Item extends Entity { } - public function __toHtml() { + public function _toHtml() { $return = ''; $id = $this->get_id(); diff --git a/src/classes/entities/class-tainacan-log.php b/src/classes/entities/class-tainacan-log.php index f91fe8799..3b47d5322 100644 --- a/src/classes/entities/class-tainacan-log.php +++ b/src/classes/entities/class-tainacan-log.php @@ -44,8 +44,8 @@ class Log extends Entity { /** * @return array */ - public function __toArray() { - $array_log = parent::__toArray(); + public function _toArray() { + $array_log = parent::_toArray(); $array_log['user_name'] = $this->get_user_name(); diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 8809c3b7d..e71853506 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -55,8 +55,8 @@ class Term extends Entity { return 'Hello, my name is '. $this->get_name(); } - public function __toArray(){ - $term_array = parent::__toArray(); + public function _toArray(){ + $term_array = parent::_toArray(); $term_id = $term_array['term_id']; @@ -257,7 +257,7 @@ class Term extends Entity { } - public function __toHtml() { + public function _toHtml() { $return = ''; $id = $this->get_id(); diff --git a/src/classes/field-types/category/class-tainacan-category.php b/src/classes/field-types/category/class-tainacan-category.php index 598baa3e0..473f32ef0 100644 --- a/src/classes/field-types/category/class-tainacan-category.php +++ b/src/classes/field-types/category/class-tainacan-category.php @@ -154,7 +154,7 @@ class Category extends Field_Type { foreach ( $value as $term ) { if ( $term instanceof \Tainacan\Entities\Term ) { - $return .= $term->__toHtml(); + $return .= $term->_toHtml(); } $count ++; @@ -168,7 +168,7 @@ class Category extends Field_Type { } else { if ( $value instanceof \Tainacan\Entities\Term ) { - $return .= $value->__toHtml(); + $return .= $value->_toHtml(); } } diff --git a/src/classes/field-types/field-type/class-tainacan-field-type.php b/src/classes/field-types/field-type/class-tainacan-field-type.php index 73e2abecf..a40704bfe 100644 --- a/src/classes/field-types/field-type/class-tainacan-field-type.php +++ b/src/classes/field-types/field-type/class-tainacan-field-type.php @@ -160,7 +160,7 @@ abstract class Field_Type { } - public function __toArray(){ + public function _toArray(){ $attributes = []; $attributes['errors'] = $this->get_errors(); diff --git a/src/classes/field-types/relationship/class-tainacan-relationship.php b/src/classes/field-types/relationship/class-tainacan-relationship.php index 604e4bfe4..b2711f068 100644 --- a/src/classes/field-types/relationship/class-tainacan-relationship.php +++ b/src/classes/field-types/relationship/class-tainacan-relationship.php @@ -90,7 +90,7 @@ class Relationship extends Field_Type { $item = new \Tainacan\Entities\Item($item_id); if ( $item instanceof \Tainacan\Entities\Item ) { - $return .= $item->__toHtml(); + $return .= $item->_toHtml(); } $count ++; @@ -112,7 +112,7 @@ class Relationship extends Field_Type { $item = new \Tainacan\Entities\Item($value); if ( $item instanceof \Tainacan\Entities\Item ) { - $return .= $item->__toHtml(); + $return .= $item->_toHtml(); } } catch (Exception $e) { diff --git a/src/classes/filter-types/filter-type/class-tainacan-filter-type.php b/src/classes/filter-types/filter-type/class-tainacan-filter-type.php index 173f6ae6b..6824dbb29 100644 --- a/src/classes/filter-types/filter-type/class-tainacan-filter-type.php +++ b/src/classes/filter-types/filter-type/class-tainacan-filter-type.php @@ -50,7 +50,7 @@ abstract class Filter_Type { /** * @return array */ - public function __toArray(){ + public function _toArray(){ $attributes = []; $attributes['className'] = get_class($this); diff --git a/src/exposers/class-tainacan-exposers.php b/src/exposers/class-tainacan-exposers.php index 953fd00d4..7b44f2533 100644 --- a/src/exposers/class-tainacan-exposers.php +++ b/src/exposers/class-tainacan-exposers.php @@ -98,7 +98,7 @@ class Exposers { $items_metadata = $item->get_fields(); $prepared_item = []; foreach ($items_metadata as $item_metadata){ - array_push($prepared_item, $item_metadata->__toArray()); + array_push($prepared_item, $item_metadata->_toArray()); } $item_arr = $prepared_item; } @@ -221,7 +221,7 @@ class Exposers { if( $type === false || // do not have a exposer type $type->get_mappers() === true || // the type accept all mappers - ( is_array($type->mappers) && in_array($body['exposer-map'], $type->get_mappers()) ) ) { // the current mapper is accepted by type + ( is_array($type->get_mappers()) && in_array($body['exposer-map'], $type->get_mappers()) ) ) { // the current mapper is accepted by type $mapper = $Tainacan_Exposers->check_class_name($body['exposer-map'], true, self::MAPPER_CLASS_PREFIX); return new $mapper; } diff --git a/src/theme-helper/class-tainacan-theme-helper.php b/src/theme-helper/class-tainacan-theme-helper.php index dc9067546..5e9f17b93 100644 --- a/src/theme-helper/class-tainacan-theme-helper.php +++ b/src/theme-helper/class-tainacan-theme-helper.php @@ -20,29 +20,29 @@ class Theme_Helper { private function __construct() { - add_filter( 'the_content', [&$this, 'the_content_filter'] ); + add_filter( 'the_content', [$this, 'the_content_filter'] ); // Replace collections permalink to post type archive if cover not enabled - add_filter('post_type_link', array(&$this, 'permalink_filter'), 10, 3); + add_filter('post_type_link', array($this, 'permalink_filter'), 10, 3); // Replace single query to the page content set as cover for the colllection // Redirect to post type archive if no cover page is set - add_action('wp', array(&$this, 'collection_single_redirect')); + add_action('wp', array($this, 'collection_single_redirect')); - add_action('wp_print_scripts', array(&$this, 'enqueue_scripts')); + add_action('wp_print_scripts', array($this, 'enqueue_scripts')); // make archive for terms work with items - add_action('pre_get_posts', array(&$this, 'tax_archive_pre_get_posts')); + add_action('pre_get_posts', array($this, 'tax_archive_pre_get_posts')); - add_action('archive_template_hierarchy', array(&$this, 'items_template_hierachy')); - add_action('single_template_hierarchy', array(&$this, 'items_template_hierachy')); + add_action('archive_template_hierarchy', array($this, 'items_template_hierachy')); + add_action('single_template_hierarchy', array($this, 'items_template_hierachy')); - add_filter('theme_mod_header_image', array(&$this, 'header_image')); + add_filter('theme_mod_header_image', array($this, 'header_image')); - add_filter('get_the_archive_title', array(&$this, 'filter_archive_title')); + add_filter('get_the_archive_title', array($this, 'filter_archive_title')); - add_shortcode( 'tainacan-search', array(&$this, 'search_shortcode')); + add_shortcode( 'tainacan-search', array($this, 'search_shortcode')); } diff --git a/tests/factories/class-tainacan-entity-factory.php b/tests/factories/class-tainacan-entity-factory.php index c55484112..6ae2b01bf 100644 --- a/tests/factories/class-tainacan-entity-factory.php +++ b/tests/factories/class-tainacan-entity-factory.php @@ -83,19 +83,19 @@ class Entity_Factory { } elseif (empty($args) && !$is_validated_and_in_db) { try { - $this->entity->set_name( "$type " . random_int( 0, 10000 ) . " for test" ); + $this->entity->set_name( "$type " . rand( 0, 10000 ) . " for test" ); $this->entity->set_description( 'It is only for test' ); - } catch (\Error $exception){ - $this->entity->set_title( "$type " . random_int( 0, 10000 ) . " for test" ); + } catch (\Exception $exception){ + $this->entity->set_title( "$type " . rand( 0, 10000 ) . " for test" ); $this->entity->set_description( 'It is only for test' ); } } elseif (empty($args) && $is_validated_and_in_db) { try { - $this->entity->set_name( "$type " . random_int( 0, 10000 ) . " for test" ); + $this->entity->set_name( "$type " . rand( 0, 10000 ) . " for test" ); $this->entity->set_description( 'It is only for test' ); - } catch (\Error $exception){ - $this->entity->set_title( "$type " . random_int( 0, 10000 ) . " for test" ); + } catch (\Exception $exception){ + $this->entity->set_title( "$type " . rand( 0, 10000 ) . " for test" ); $this->entity->set_description( 'It is only for test' ); } @@ -104,7 +104,7 @@ class Entity_Factory { } else { throw new \InvalidArgumentException('One or more arguments are invalid.'); } - } catch (\Error $exception){ + } catch (\Exception $exception){ echo "\n" . $exception->getMessage() . "\n"; } diff --git a/tests/test-filters.php b/tests/test-filters.php index f8e1eb4e9..8b3f01054 100644 --- a/tests/test-filters.php +++ b/tests/test-filters.php @@ -135,13 +135,13 @@ class Filters extends TAINACAN_UnitTestCase { $filter = $this->tainacan_entity_factory->create_entity( 'filter', - array( - 'name' => 'filtro', - 'collection' => $collection, - 'description' => 'descricao', - 'field' => $field2, - 'filter_type' => $autocomplete - ), + array( + 'name' => 'filtro', + 'collection' => $collection, + 'description' => 'descricao', + 'field' => $field2, + 'filter_type' => $autocomplete + ), true ); @@ -155,11 +155,11 @@ class Filters extends TAINACAN_UnitTestCase { $filter2 = $this->tainacan_entity_factory->create_entity( 'filter', array( - 'name' => 'filtro 2', - 'collection' => $collection, - 'description' => 'descricao', - 'field' => $field2, - 'filter_type' => $custom_interval + 'name' => 'filtro 2', + 'collection' => $collection, + 'description' => 'descricao', + 'field' => $field2, + 'filter_type' => $custom_interval ), true ); diff --git a/verify_compat.sh b/verify_compat.sh new file mode 100755 index 000000000..a99123e2c --- /dev/null +++ b/verify_compat.sh @@ -0,0 +1,8 @@ +touch report.txt +echo 'Verifing potencial incompatibilities with php 5.6 or greater' + +echo 'W is Warning' +echo 'E is Error' + +./src/vendor/bin/phpcs -p . --standard=PHPCompatibility --extensions=php --ignore=*/node_modules/*,*/src/vendor/* --report-file=./report.txt --runtime-set testVersion 5.6 +