From 6f705c856db915a42facdf1f8217445fbd5fc422 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Mon, 12 Aug 2024 20:24:22 +0100 Subject: [PATCH 01/56] Deploy: Don't include .git/ directory --- .distignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.distignore b/.distignore index 19f14f4..eb83f6e 100644 --- a/.distignore +++ b/.distignore @@ -3,6 +3,7 @@ # The deploy Action will use rsync + .distignore if the .distignore exists, # so it doesn't care what may or may not be ignored via .gitignore. +/.git/ /.github/ /bin/ /tests/ From b7af9af4e1065dd7696cb7ae8e9990f9699e8ada Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 16:43:49 +0100 Subject: [PATCH 02/56] CS: Run PHPCBF No intentional changes in behaviour - mostly whitespace changes to ensure more compliance with coding standards. --- functions.php | 7 +- includes/class-zoninator-api-controller.php | 207 +- .../class-zoninator-api-filter-search.php | 1 - .../class-zoninator-api-schema-converter.php | 16 +- .../class-zoninator-rest-bootstrap.php | 10 +- .../class-zoninator-rest-classloader.php | 10 +- .../class-zoninator-rest-controller.php | 11 +- .../class-zoninator-rest-environment.php | 18 +- .../class-zoninator-rest-model.php | 65 +- ...class-zoninator-rest-controller-action.php | 18 +- ...class-zoninator-rest-controller-bundle.php | 3 +- .../class-zoninator-rest-controller-crud.php | 18 +- ...ss-zoninator-rest-controller-extension.php | 18 +- .../class-zoninator-rest-controller-model.php | 16 +- .../class-zoninator-rest-controller-route.php | 10 +- ...ass-zoninator-rest-controller-settings.php | 4 +- .../data/class-zoninator-rest-data-mapper.php | 12 +- .../class-zoninator-rest-data-serializer.php | 4 +- ...ass-zoninator-rest-data-store-abstract.php | 4 +- ...ninator-rest-data-store-customposttype.php | 46 +- .../class-zoninator-rest-data-store-nil.php | 2 +- ...class-zoninator-rest-data-store-option.php | 15 +- ...class-zoninator-rest-field-declaration.php | 42 +- ...ninator-rest-field-declaration-builder.php | 1 - ...s-zoninator-rest-interfaces-data-store.php | 2 +- ...ator-rest-interfaces-model-declaration.php | 5 +- ...class-zoninator-rest-model-declaration.php | 2 +- .../class-zoninator-rest-model-definition.php | 30 +- .../class-zoninator-rest-model-settings.php | 25 +- ...ss-zoninator-rest-model-validationdata.php | 2 +- ...inator-rest-model-declaration-settings.php | 28 +- .../class-zoninator-rest-type-nullable.php | 2 +- .../class-zoninator-rest-type-registry.php | 30 +- .../class-zoninator-rest-type-typedarray.php | 4 +- widget.zone-posts.php | 33 +- zoninator.php | 2434 +++++++++-------- 36 files changed, 1659 insertions(+), 1496 deletions(-) diff --git a/functions.php b/functions.php index 4f9cd2e..74ad95c 100644 --- a/functions.php +++ b/functions.php @@ -7,6 +7,7 @@ function z_get_zoninator() { /** * Get a list of all zones + * * @return array List of all zones */ function z_get_zones() { @@ -68,9 +69,11 @@ function z_get_post_zones( $post_id = 0 ) { } function z_get_loop_post_id_or_default( $post_id = 0 ) { - if( ! $post_id ) { + if ( ! $post_id ) { global $post; - if( $post && isset( $post->ID ) ) $post_id = $post->ID; + if ( $post && isset( $post->ID ) ) { + $post_id = $post->ID; + } } return $post_id; } diff --git a/includes/class-zoninator-api-controller.php b/includes/class-zoninator-api-controller.php index 748e8cb..208c7ca 100644 --- a/includes/class-zoninator-api-controller.php +++ b/includes/class-zoninator-api-controller.php @@ -7,21 +7,21 @@ * Class Zoninator_Api_Controller */ class Zoninator_Api_Controller extends Zoninator_REST_Controller { - const ZONE_ITEM_URL_REGEX = '/zones/(?P[\d]+)'; - const ZONE_ITEM_POSTS_URL_REGEX = '/zones/(?P[\d]+)/posts'; + const ZONE_ITEM_URL_REGEX = '/zones/(?P[\d]+)'; + const ZONE_ITEM_POSTS_URL_REGEX = '/zones/(?P[\d]+)/posts'; const ZONE_ITEM_POSTS_POST_REGEX = '/zones/(?P[\d]+)/posts/(?P\d+)'; - const INVALID_ZONE_ID = 'invalid-zone-id'; - const INVALID_POST_ID = 'invalid-post-id'; - const ZONE_ID_POST_ID_REQUIRED = 'zone-id-post-id-required'; + const INVALID_ZONE_ID = 'invalid-zone-id'; + const INVALID_POST_ID = 'invalid-post-id'; + const ZONE_ID_POST_ID_REQUIRED = 'zone-id-post-id-required'; const ZONE_ID_POST_IDS_REQUIRED = 'zone-id-post-ids-required'; - const ZONE_ID_REQUIRED = 'zone-id-required'; - const ZONE_FEED_ERROR = 'zone-feed-error'; - const TERM_REQUIRED = 'term-required'; - const PERMISSION_DENIED = 'permission-denied'; - const ZONE_NOT_FOUND = 'zone-not-found'; - const POST_NOT_FOUND = 'post-not-found'; - const INVALID_ZONE_SETTINGS = 'invalid-zone-settings'; + const ZONE_ID_REQUIRED = 'zone-id-required'; + const ZONE_FEED_ERROR = 'zone-feed-error'; + const TERM_REQUIRED = 'term-required'; + const PERMISSION_DENIED = 'permission-denied'; + const ZONE_NOT_FOUND = 'zone-not-found'; + const POST_NOT_FOUND = 'post-not-found'; + const INVALID_ZONE_SETTINGS = 'invalid-zone-settings'; /** * Instance * @@ -43,7 +43,7 @@ class Zoninator_Api_Controller extends Zoninator_REST_Controller { */ function __construct( $instance ) { $this->instance = $instance; - $this->base = '/'; + $this->base = '/'; } /** @@ -109,9 +109,11 @@ function get_zones( $request ) { $results = $this->instance->get_zones(); if ( is_wp_error( $results ) ) { - return $this->bad_request( array( - 'message' => $results->get_error_message(), - ) ); + return $this->bad_request( + array( + 'message' => $results->get_error_message(), + ) + ); } $zones = array_map( array( $this, '_filter_zone_properties' ), $results ); @@ -126,21 +128,27 @@ function get_zones( $request ) { * @return WP_Error|WP_REST_Response */ function create_zone( $request ) { - $name = $this->_get_param( $request, 'name', '' ); - $slug = $this->_get_param( $request, 'slug', $name ); + $name = $this->_get_param( $request, 'name', '' ); + $slug = $this->_get_param( $request, 'slug', $name ); $description = $this->_get_param( $request, 'description', '' ); - $result = $this->instance->insert_zone( $slug, $name, array( - 'description' => $description, - ) ); + $result = $this->instance->insert_zone( + $slug, + $name, + array( + 'description' => $description, + ) + ); if ( is_wp_error( $result ) ) { - return $this->bad_request( array( - 'message' => $result->get_error_message(), - ) ); + return $this->bad_request( + array( + 'message' => $result->get_error_message(), + ) + ); } - $zone = $this->instance->get_zone( $result[ 'term_id' ] ); + $zone = $this->instance->get_zone( $result['term_id'] ); return $this->created( $this->_filter_zone_properties( $zone ) ); } @@ -152,12 +160,12 @@ function create_zone( $request ) { * @return WP_Error|WP_REST_Response */ function update_zone( $request ) { - $zone_id = $this->_get_param( $request, 'zone_id', 0, 'absint' ); - $name = $this->_get_param( $request, 'name', '' ); - $slug = $this->_get_param( $request, 'slug', '' ); + $zone_id = $this->_get_param( $request, 'zone_id', 0, 'absint' ); + $name = $this->_get_param( $request, 'name', '' ); + $slug = $this->_get_param( $request, 'slug', '' ); $description = $this->_get_param( $request, 'description', '', 'strip_tags' ); - $zone = $this->instance->get_zone( $zone_id ); + $zone = $this->instance->get_zone( $zone_id ); $update_params = array(); if ( ! $zone ) { @@ -165,23 +173,25 @@ function update_zone( $request ) { } if ( $name ) { - $update_params[ 'name' ] = $name; + $update_params['name'] = $name; } if ( $slug ) { - $update_params[ 'slug' ] = $slug; + $update_params['slug'] = $slug; } if ( $description ) { - $update_params[ 'details' ] = array( 'description' => $description ); + $update_params['details'] = array( 'description' => $description ); } $result = $this->instance->update_zone( $zone, $update_params ); if ( is_wp_error( $result ) ) { - return $this->bad_request( array( - 'message' => $result->get_error_message(), - ) ); + return $this->bad_request( + array( + 'message' => $result->get_error_message(), + ) + ); } return $this->ok( array( 'success' => true ) ); @@ -205,9 +215,11 @@ function delete_zone( $request ) { $result = $this->instance->delete_zone( $zone ); if ( is_wp_error( $result ) ) { - return $this->bad_request( array( - 'message' => $result->get_error_message(), - ) ); + return $this->bad_request( + array( + 'message' => $result->get_error_message(), + ) + ); } return $this->ok( array( 'success' => true ) ); @@ -242,7 +254,7 @@ public function get_zone_posts( $request ) { * @return WP_Error|WP_REST_Response */ function update_zone_posts( $request ) { - $zone_id = $this->_get_param( $request, 'zone_id', 0, 'absint' ); + $zone_id = $this->_get_param( $request, 'zone_id', 0, 'absint' ); $post_ids = $this->_get_param( $request, 'post_ids', array() ); if ( ! $this->instance->get_zone( $zone_id ) ) { @@ -252,9 +264,11 @@ function update_zone_posts( $request ) { $posts = array_map( 'get_post', $post_ids ); if ( count( $posts ) !== count( array_filter( $posts ) ) ) { - return $this->bad_request( array( - 'message' => $this->translations[ self::INVALID_POST_ID ], - ) ); + return $this->bad_request( + array( + 'message' => $this->translations[ self::INVALID_POST_ID ], + ) + ); } $result = $this->instance->add_zone_posts( $zone_id, $posts ); @@ -275,7 +289,7 @@ function update_zone_posts( $request ) { function zone_update_lock( $request ) { $zone_id = $this->_get_param( $request, 'zone_id', 0, 'absint' ); if ( ! $zone_id ) { - return $this->_bad_request(self::ZONE_ID_REQUIRED, __('zone id required', 'zoninator')); + return $this->_bad_request( self::ZONE_ID_REQUIRED, __( 'zone id required', 'zoninator' ) ); } $zone = $this->instance->get_zone( $zone_id ); @@ -286,18 +300,24 @@ function zone_update_lock( $request ) { $zone_locked = $this->instance->is_zone_locked( $zone ); if ( $zone_locked ) { $locking_user = get_userdata( $zone_locked ); - return new WP_REST_Response( array( - 'zone_id' => $this->instance->get_zone_id( $zone ), - 'blocked' => true, - ), 400); + return new WP_REST_Response( + array( + 'zone_id' => $this->instance->get_zone_id( $zone ), + 'blocked' => true, + ), + 400 + ); } $this->instance->lock_zone( $zone_id ); - return new WP_REST_Response( array( - 'zone_id' => $this->instance->get_zone_id( $zone ), - 'timeout' => $this->instance->zone_lock_period, - 'max_lock_period' => $this->instance->zone_max_lock_period, - ), 200 ); + return new WP_REST_Response( + array( + 'zone_id' => $this->instance->get_zone_id( $zone ), + 'timeout' => $this->instance->zone_lock_period, + 'max_lock_period' => $this->instance->zone_max_lock_period, + ), + 200 + ); } /** @@ -347,7 +367,7 @@ public function is_numeric( $item ) { } public function is_numeric_array( $items ) { - return count( $items ) === count( array_filter( $items, 'is_numeric') ); + return count( $items ) === count( array_filter( $items, 'is_numeric' ) ); } public function sanitize_string( $item ) { @@ -357,8 +377,8 @@ public function sanitize_string( $item ) { /** * @param WP_REST_Request $object * @param $var - * @param string $default - * @param string $sanitize_callback + * @param string $default + * @param string $sanitize_callback * @return array|mixed|null|string */ private function _get_param( $object, $var, $default = '', $sanitize_callback = '' ) { @@ -374,44 +394,44 @@ private function _get_param( $object, $var, $default = '', $sanitize_callback = public function _params_for_create_zone() { return array( - 'name' => array( - 'type' => 'string', + 'name' => array( + 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize_string' ), - 'default' => '', - 'required' => false + 'default' => '', + 'required' => false, ), - 'slug' => array( - 'type' => 'string', + 'slug' => array( + 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize_string' ), - 'default' => '', - 'required' => false, + 'default' => '', + 'required' => false, ), 'description' => array( - 'type' => 'string', + 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize_string' ), - 'default' => '', - 'required' => false, - ) + 'default' => '', + 'required' => false, + ), ); } public function _params_for_update_zone() { return array( - 'name' => array( - 'type' => 'string', + 'name' => array( + 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize_string' ), - 'required' => false + 'required' => false, ), - 'slug' => array( - 'type' => 'string', + 'slug' => array( + 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize_string' ), - 'required' => false, + 'required' => false, ), 'description' => array( - 'type' => 'string', + 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize_string' ), - 'required' => false, - ) + 'required' => false, + ), ); } @@ -421,35 +441,38 @@ public function _get_zone_id_param() { 'type' => 'integer', 'validate_callback' => array( $this, 'is_numeric' ), 'sanitize_callback' => 'absint', - 'required' => true - ) + 'required' => true, + ), ); } public function _get_zone_post_rest_route_params() { $zone_params = $this->_get_zone_id_param(); - return array_merge( array( - 'post_ids' => array( - 'type' => 'array', - 'validate_callback' => array( $this, 'is_numeric_array' ), - 'required' => true, - 'items' => array( 'type' => 'integer' ), + return array_merge( + array( + 'post_ids' => array( + 'type' => 'array', + 'validate_callback' => array( $this, 'is_numeric_array' ), + 'required' => true, + 'items' => array( 'type' => 'integer' ), + ), ), - ), $zone_params ); + $zone_params + ); } public function _filter_zone_properties( $zone ) { $data = $zone->to_array(); return array( - 'term_id' => $data[ 'term_id' ], - 'slug' => $data[ 'slug' ], - 'name' => $data[ 'name' ], - 'description' => $data[ 'description' ], + 'term_id' => $data['term_id'], + 'slug' => $data['slug'], + 'name' => $data['name'], + 'description' => $data['description'], ); } - private function _bad_request($code, $message) { + private function _bad_request( $code, $message ) { return new WP_Error( $code, $message, array( 'status' => 400 ) ); } @@ -457,9 +480,9 @@ private function _bad_request($code, $message) { * @param $zone_id * @return bool|WP_Error */ - private function _permissions_check($action, $zone_id = null ) { + private function _permissions_check( $action, $zone_id = null ) { if ( ! $this->instance->check( $action, $zone_id ) ) { - return new WP_Error( self::PERMISSION_DENIED, __('Sorry, you\'re not supposed to do that...', 'zoninator' ) ); + return new WP_Error( self::PERMISSION_DENIED, __( 'Sorry, you\'re not supposed to do that...', 'zoninator' ) ); } return true; } diff --git a/includes/class-zoninator-api-filter-search.php b/includes/class-zoninator-api-filter-search.php index 3dbaeef..2da3039 100644 --- a/includes/class-zoninator-api-filter-search.php +++ b/includes/class-zoninator-api-filter-search.php @@ -75,4 +75,3 @@ function date_before_set( $model, $item ) { return $this->strip_tags( $this->strip_slashes( $item ) ); } } - diff --git a/includes/class-zoninator-api-schema-converter.php b/includes/class-zoninator-api-schema-converter.php index 45f7751..6b23284 100644 --- a/includes/class-zoninator-api-schema-converter.php +++ b/includes/class-zoninator-api-schema-converter.php @@ -8,9 +8,9 @@ class Zoninator_Api_Schema_Converter { * @return mixed */ public function as_schema( $model_definition ) { - $fields = $model_definition->get_fields(); + $fields = $model_definition->get_fields(); $properties = array(); - $required = array(); + $required = array(); foreach ( $fields as $field_declaration ) { /** * Our declaration @@ -23,9 +23,9 @@ public function as_schema( $model_definition ) { } } $schema = array( - '$schema' => 'http://json-schema.org/schema#', - 'title' => $model_definition->get_name(), - 'type' => 'object', + '$schema' => 'http://json-schema.org/schema#', + 'title' => $model_definition->get_name(), + 'type' => 'object', 'properties' => (array) apply_filters( 'rest_api_schema_properties', $properties, $model_definition ), ); @@ -53,9 +53,9 @@ public function as_args( $model_definition ) { * @var Zoninator_REST_Field_Declaration $field_declaration */ $arg = array( - 'description' => $field_declaration->get_description(), - 'type' => $type_schema['type'], - 'required' => $field_declaration->is_required(), + 'description' => $field_declaration->get_description(), + 'type' => $type_schema['type'], + 'required' => $field_declaration->is_required(), ); if ( ! $field_declaration->is_required() ) { diff --git a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php index 0af4812..29feb30 100644 --- a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php +++ b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php @@ -58,7 +58,7 @@ public static function is_compatible() { * @return string */ public static function get_base_dir() { - return untrailingslashit( dirname( __FILE__ ) ); + return untrailingslashit( __DIR__ ); } /** @@ -69,10 +69,10 @@ public static function get_base_dir() { */ public static function create( $class_loader = null ) { if ( empty( $class_loader ) ) { - include_once( 'interfaces/class-zoninator-rest-interfaces-classloader.php' ); - include_once( 'class-zoninator-rest-classloader.php' ); - $prefix = str_replace( '_Bootstrap', '', __CLASS__ ); - $base_dir = self::get_base_dir(); + include_once 'interfaces/class-zoninator-rest-interfaces-classloader.php'; + include_once 'class-zoninator-rest-classloader.php'; + $prefix = str_replace( '_Bootstrap', '', __CLASS__ ); + $base_dir = self::get_base_dir(); $class_loader = new Zoninator_REST_Classloader( $prefix, $base_dir ); } return new self( $class_loader ); diff --git a/lib/zoninator_rest/class-zoninator-rest-classloader.php b/lib/zoninator_rest/class-zoninator-rest-classloader.php index 2816525..2bf45a2 100644 --- a/lib/zoninator_rest/class-zoninator-rest-classloader.php +++ b/lib/zoninator_rest/class-zoninator-rest-classloader.php @@ -43,9 +43,9 @@ class Zoninator_REST_Classloader implements Zoninator_REST_Interfaces_Classloade * @throws Exception Throws if an invalid directory is provided. */ public function __construct( $prefix, $base_dir ) { - $this->loaded_classes = array(); - $this->prefix = $prefix; - $this->base_dir = $base_dir; + $this->loaded_classes = array(); + $this->prefix = $prefix; + $this->base_dir = $base_dir; if ( ! is_dir( $this->base_dir ) ) { throw new Exception( 'base_dir does not exist: ' . $this->base_dir ); } @@ -86,7 +86,7 @@ public function get_path_to_class_file( $class_name ) { public function class_name_to_relative_path( $class_name, $prefix = null ) { $lowercase = strtolower( $this->prefixed_class_name( $class_name, $prefix ) ); $file_name = 'class-' . str_replace( '_', '-', $lowercase ) . '.php'; - $parts = explode( '_', strtolower( $this->strip_prefix( $class_name, $prefix ) ) ); + $parts = explode( '_', strtolower( $this->strip_prefix( $class_name, $prefix ) ) ); array_pop( $parts ); $parts[] = $file_name; return implode( DIRECTORY_SEPARATOR, $parts ); @@ -137,7 +137,7 @@ private function include_class_file( $path_to_the_class ) { if ( ! file_exists( $path_to_the_class ) ) { throw new Exception( $path_to_the_class . ' not found' ); } - $included = include_once( $path_to_the_class ); + $included = include_once $path_to_the_class; $this->loaded_classes[ $path_to_the_class ] = $included; return $this; diff --git a/lib/zoninator_rest/class-zoninator-rest-controller.php b/lib/zoninator_rest/class-zoninator-rest-controller.php index e64fa18..e9f8bd4 100644 --- a/lib/zoninator_rest/class-zoninator-rest-controller.php +++ b/lib/zoninator_rest/class-zoninator-rest-controller.php @@ -171,9 +171,12 @@ public function bad_request( $data ) { * @return WP_REST_Response */ public function not_found( $message ) { - return $this->respond( array( - 'message' => $message, - ), self::HTTP_NOT_FOUND ); + return $this->respond( + array( + 'message' => $message, + ), + self::HTTP_NOT_FOUND + ); } /** @@ -260,7 +263,7 @@ function permissions_check( $request, $action = 'any' ) { * @return Zoninator_REST_Controller_Route */ function add_route( $pattern = '' ) { - $route = new Zoninator_REST_Controller_Route( $this, $pattern ); + $route = new Zoninator_REST_Controller_Route( $this, $pattern ); $this->routes[ $pattern ] = $route; return $this->routes[ $pattern ]; } diff --git a/lib/zoninator_rest/class-zoninator-rest-environment.php b/lib/zoninator_rest/class-zoninator-rest-environment.php index 619b5b2..276130b 100644 --- a/lib/zoninator_rest/class-zoninator-rest-environment.php +++ b/lib/zoninator_rest/class-zoninator-rest-environment.php @@ -20,8 +20,8 @@ */ class Zoninator_REST_Environment { const REGISTRABLE = 'IRegistrable'; - const BUNDLES = 'Bundles'; - const MODELS = 'Models'; + const BUNDLES = 'Bundles'; + const MODELS = 'Models'; /** * This environment's registered REST bundles @@ -75,12 +75,12 @@ class Zoninator_REST_Environment { * @param Zoninator_REST_Bootstrap $bootstrap The bootstrap. */ public function __construct( $bootstrap ) { - $this->bootstrap = $bootstrap; - $this->has_started = false; - $this->rest_apis = array(); - $this->variables = array(); + $this->bootstrap = $bootstrap; + $this->has_started = false; + $this->rest_apis = array(); + $this->variables = array(); $this->model_definitions = array(); - $this->type_registry = new Zoninator_REST_Type_Registry(); + $this->type_registry = new Zoninator_REST_Type_Registry(); $this->type_registry->initialize( $this ); // initialize our array vars. $this->array_var( self::MODELS ) @@ -93,7 +93,7 @@ public function __construct( $bootstrap ) { * * All builders are evaluated lazily when needed * - * @param string $where The queue to push the builder to. + * @param string $where The queue to push the builder to. * @param Zoninator_REST_Interfaces_Builder $builder The builder to push. * * @return Zoninator_REST_Environment $this @@ -402,7 +402,7 @@ function define_model( $declaration ) { */ private function add_rest_bundle( $bundle ) { Zoninator_REST_Expect::is_a( $bundle, 'Zoninator_REST_Interfaces_Controller_Bundle' ); - $key = $bundle->get_prefix(); + $key = $bundle->get_prefix(); $this->rest_apis[ $key ] = $bundle; return $this; } diff --git a/lib/zoninator_rest/class-zoninator-rest-model.php b/lib/zoninator_rest/class-zoninator-rest-model.php index 12df88f..b6998cf 100644 --- a/lib/zoninator_rest/class-zoninator-rest-model.php +++ b/lib/zoninator_rest/class-zoninator-rest-model.php @@ -75,7 +75,7 @@ function __construct( $data = array(), $args = array() ) { $data = $this->deserialize( $data ); } $this->raw_data = $data; - $data_keys = array_keys( $data ); + $data_keys = array_keys( $data ); foreach ( $data_keys as $key ) { $this->set( $key, $this->raw_data[ $key ] ); @@ -93,7 +93,7 @@ function __construct( $data = array(), $args = array() ) { */ public function get( $field_name, $args = array() ) { Zoninator_REST_Expect::that( $this->has( $field_name ), 'Field ' . $field_name . 'is not defined' ); - $fields = $this->get_fields(); + $fields = $this->get_fields(); $field_declaration = $fields[ $field_name ]; $this->set_field_if_unset( $field_declaration ); @@ -148,7 +148,7 @@ public function has( $field ) { */ public function validate() { $validation_errors = array(); - $fields = self::get_fields(); + $fields = self::get_fields(); foreach ( $fields as $key => $field_declaration ) { $is_valid = $this->run_field_validations( $field_declaration ); if ( is_wp_error( $is_valid ) ) { @@ -174,8 +174,8 @@ public function sanitize() { * * @var Zoninator_REST_Field_Declaration $field_declaration */ - $field_name = $field_declaration->get_name(); - $value = $this->get( $field_name ); + $field_name = $field_declaration->get_name(); + $value = $this->get( $field_name ); $custom_sanitization = $field_declaration->get_sanitizer(); if ( ! empty( $custom_sanitization ) ) { $value = $this->call( $custom_sanitization, array( $this, $value ) ); @@ -217,11 +217,13 @@ protected function run_field_validations( $field_declaration ) { foreach ( $field_declaration->get_validations() as $validation ) { $result = $this->call( $validation, array( $value ) ); if ( is_wp_error( $result ) ) { - $result->add_data(array( - 'reason' => $result->get_error_messages(), - 'field' => $field_declaration->get_data_transfer_name(), - 'value' => $value, - ) ); + $result->add_data( + array( + 'reason' => $result->get_error_messages(), + 'field' => $field_declaration->get_data_transfer_name(), + 'value' => $value, + ) + ); return $result; } } @@ -236,8 +238,8 @@ protected function run_field_validations( $field_declaration ) { * @return mixed */ private function prepare_value( $field_declaration ) { - $key = $field_declaration->get_name(); - $value = $this->data[ $key ]; + $key = $field_declaration->get_name(); + $value = $this->data[ $key ]; $before_return = $field_declaration->before_get(); if ( isset( $before_return ) && ! empty( $before_return ) ) { $value = $this->call( $before_return, array( $value, $key ) ); @@ -279,7 +281,7 @@ public function get_fields( $filter_by_type = null ) { */ $instance = new $class_name(); if ( ! isset( self::$fields_by_class_name[ $class_name ] ) ) { - $fields = $instance->declare_fields(); + $fields = $instance->declare_fields(); self::$fields_by_class_name[ $class_name ] = self::initialize_field_map( $fields ); } @@ -317,7 +319,7 @@ private static function initialize_field_map( $declared_field_builders ) { * * @var Zoninator_REST_Field_Declaration $field Field Builder. */ - $field = $field_builder->build(); + $field = $field_builder->build(); $fields[ $field->get_name() ] = $field; } return $fields; @@ -373,7 +375,7 @@ public function get_environment() { */ public function with_environment( $environment ) { Zoninator_REST_Expect::is_a( $environment, 'Zoninator_REST_Environment' ); - $class_name = get_class( $this ); + $class_name = get_class( $this ); self::$environments_by_class_name[ $class_name ] = $environment; return $this; } @@ -453,7 +455,7 @@ public function get_dto_field_mappings() { function to_dto() { $result = array(); foreach ( $this->get_dto_field_mappings() as $mapping_name => $field_name ) { - $value = $this->get( $field_name ); + $value = $this->get( $field_name ); $result[ $mapping_name ] = $value; } @@ -469,7 +471,7 @@ function to_dto() { */ private function map_data( $data, $updating = false ) { $request_data = array(); - $fields = $this->get_fields(); + $fields = $this->get_fields(); foreach ( $fields as $field ) { /** * Field @@ -479,10 +481,10 @@ private function map_data( $data, $updating = false ) { if ( $field->is_kind( Zoninator_REST_Field_Declaration::DERIVED ) ) { continue; } - $dto_name = $field->get_data_transfer_name(); + $dto_name = $field->get_data_transfer_name(); $field_name = $field->get_name(); if ( isset( $data[ $dto_name ] ) && ! ( $updating && $field->is_primary() ) ) { - $value = $data[ $dto_name ]; + $value = $data[ $dto_name ]; $request_data[ $field_name ] = $value; } } @@ -562,9 +564,12 @@ public static function from_raw_data( $post ) { } $merged_data = array_merge( $raw_post_data, $flattened_meta ); - return self::create( $merged_data, array( - 'deserialize' => true, - ) ); + return self::create( + $merged_data, + array( + 'deserialize' => true, + ) + ); } /** @@ -575,17 +580,17 @@ public static function from_raw_data( $post ) { */ public function deserialize( $data ) { $field_declarations = $this->get_fields(); - $raw_data = array(); - $post_array_keys = array_keys( $data ); + $raw_data = array(); + $post_array_keys = array_keys( $data ); foreach ( $field_declarations as $declaration ) { /** * Declaration * * @var Zoninator_REST_Field_Declaration $declaration */ - $key = $declaration->get_name(); + $key = $declaration->get_name(); $mapping = $declaration->get_map_from(); - $value = null; + $value = null; if ( in_array( $key, $post_array_keys, true ) ) { // simplest case: we got a $key for this, so just map it. $value = $this->deserialize_field( $declaration, $data[ $key ] ); @@ -616,8 +621,8 @@ function serialize( $field_type = null ) { * * @var Zoninator_REST_Field_Declaration $field_declaration */ - $what_to_map_to = $field_declaration->get_map_from(); - $value = $this->get( $field_declaration->get_name() ); + $what_to_map_to = $field_declaration->get_map_from(); + $value = $this->get( $field_declaration->get_name() ); $field_values_to_insert[ $what_to_map_to ] = $this->serialize_field( $field_declaration, $value ); } @@ -628,7 +633,7 @@ function serialize( $field_type = null ) { * Deserialize * * @param Zoninator_REST_Field_Declaration $field_declaration Declaration. - * @param mixed $value Value. + * @param mixed $value Value. * @return mixed the deserialized value */ private function deserialize_field( $field_declaration, $value ) { @@ -643,7 +648,7 @@ private function deserialize_field( $field_declaration, $value ) { * Serialize * * @param Zoninator_REST_Field_Declaration $field_declaration Declaration. - * @param mixed $value Value. + * @param mixed $value Value. * @return mixed * @throws Zoninator_REST_Exception If call fails. */ diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php index a26c876..948a5aa 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php @@ -19,12 +19,12 @@ class Zoninator_REST_Controller_Action { * @var array */ private $actions_to_http_methods = array( - 'index' => WP_REST_Server::READABLE, - 'show' => WP_REST_Server::READABLE, - 'create' => WP_REST_Server::CREATABLE, + 'index' => WP_REST_Server::READABLE, + 'show' => WP_REST_Server::READABLE, + 'create' => WP_REST_Server::CREATABLE, 'update' => WP_REST_Server::EDITABLE, 'delete' => WP_REST_Server::DELETABLE, - 'any' => WP_REST_Server::ALLMETHODS, + 'any' => WP_REST_Server::ALLMETHODS, ); /** @@ -59,16 +59,16 @@ class Zoninator_REST_Controller_Action { * Zoninator_REST_Controller_Action constructor. * * @param Zoninator_REST_Controller $controller Controller. - * @param string $action_name The action Name. + * @param string $action_name The action Name. */ public function __construct( $controller, $action_name ) { $is_known_action = in_array( $action_name, array_keys( $this->actions_to_http_methods ), true ); Zoninator_REST_Expect::that( $is_known_action, 'Unknown method: ' . $action_name ); - $this->controller = $controller; - $this->action_name = $action_name; - $this->handler = null; - $this->args = null; + $this->controller = $controller; + $this->action_name = $action_name; + $this->handler = null; + $this->args = null; $this->permission_callback = null; } diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php index 328ed64..28a03ec 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php @@ -47,7 +47,7 @@ class Zoninator_REST_Controller_Bundle implements Zoninator_REST_Interfaces_Cont * @param array $endpoints Builders. */ function __construct( $bundle_prefix, $endpoints ) { - $this->prefix = $bundle_prefix; + $this->prefix = $bundle_prefix; $this->endpoints = $endpoints; } @@ -96,4 +96,3 @@ function get_prefix() { return $this->prefix; } } - diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php index 2ca226d..af73b72 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php @@ -19,12 +19,12 @@ class Zoninator_REST_Controller_CRUD extends Zoninator_REST_Controller_Model imp */ public function setup() { $this->add_route( '/' ) - ->add_action( $this->action( 'index', array( $this, 'get_items' ) ) ) + ->add_action( $this->action( 'index', array( $this, 'get_items' ) ) ) ->add_action( $this->action( 'create', array( $this, 'create_item' ) ) ); $this->add_route( '/(?P\d+)' ) - ->add_action( $this->action( 'show', array( $this, 'get_item' ) ) ) - ->add_action( $this->action( 'update', array( $this, 'update_item' ) ) ) + ->add_action( $this->action( 'show', array( $this, 'get_item' ) ) ) + ->add_action( $this->action( 'update', array( $this, 'update_item' ) ) ) ->add_action( $this->action( 'delete', array( $this, 'delete_item' ) ) ); } @@ -39,7 +39,7 @@ public function get_items( $request ) { if ( null === $item_id ) { $models = $this->get_model_data_store()->get_entities(); - $data = $this->prepare_dto( $models ); + $data = $this->prepare_dto( $models ); return $this->ok( $data ); } @@ -125,9 +125,11 @@ protected function create_or_update( $request, $is_update = false ) { return $this->bad_request( $id_or_error ); } - $dto = $this->prepare_dto( array( - 'id' => absint( $id_or_error ), - ) ); + $dto = $this->prepare_dto( + array( + 'id' => absint( $id_or_error ), + ) + ); return $is_update ? $this->ok( $dto ) : $this->created( $dto ); } @@ -158,7 +160,7 @@ public function delete_item( $request ) { * @return array */ protected function model_to_dto( $model ) { - $result = parent::model_to_dto( $model ); + $result = parent::model_to_dto( $model ); $result['_links'] = $this->add_links( $model ); return $result; } diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php index 5835429..f996c6f 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php @@ -43,7 +43,7 @@ class Zoninator_REST_Controller_Extension implements Zoninator_REST_Interfaces_R */ function __construct( $object_to_extend, $model_definition_name ) { $this->model_definition_name = $model_definition_name; - $this->object_to_extend = $object_to_extend; + $this->object_to_extend = $object_to_extend; } /** @@ -55,7 +55,7 @@ function __construct( $object_to_extend, $model_definition_name ) { * @return bool|WP_Error true if valid otherwise error. */ function register( $environment ) { - $this->environment = $environment; + $this->environment = $environment; $this->model_definition = $this->environment->model( $this->model_definition_name ); if ( ! $this->model_definition ) { return new WP_Error( 'model-not-found' ); @@ -74,10 +74,14 @@ function register( $environment ) { * @param Zoninator_REST_Field_Declaration $field Field. */ private function register_field( $field ) { - register_rest_field( $this->object_to_extend, $field->get_data_transfer_name(), array( - 'get_callback' => $field->get_reader(), - 'update_callback' => $field->get_updater(), - 'schema' => $field->as_item_schema_property(), - ) ); + register_rest_field( + $this->object_to_extend, + $field->get_data_transfer_name(), + array( + 'get_callback' => $field->get_reader(), + 'update_callback' => $field->get_updater(), + 'schema' => $field->as_item_schema_property(), + ) + ); } } diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php index 2bcaf7b..a38caa3 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php @@ -43,7 +43,7 @@ class Zoninator_REST_Controller_Model extends Zoninator_REST_Controller implemen * @param string $model_class_name A Definition or a definition name. */ public function __construct( $base, $model_class_name ) { - $this->base = $base; + $this->base = $base; $this->model_class_name = $model_class_name; } @@ -67,7 +67,7 @@ protected function get_model_prototype() { * @return bool|WP_Error true if valid otherwise error. */ public function register( $bundle, $environment ) { - $this->model_prototype = $environment->model( $this->model_class_name ); + $this->model_prototype = $environment->model( $this->model_class_name ); $this->model_data_store = $this->model_prototype->get_data_store(); return parent::register( $bundle, $environment ); } @@ -83,9 +83,9 @@ public function register( $bundle, $environment ) { */ public function get_item_schema() { $model_definition = $this->get_model_prototype(); - $fields = $model_definition->get_fields(); - $properties = array(); - $required = array(); + $fields = $model_definition->get_fields(); + $properties = array(); + $required = array(); foreach ( $fields as $field_declaration ) { /** * Our declaration @@ -98,9 +98,9 @@ public function get_item_schema() { } } $schema = array( - '$schema' => 'http://json-schema.org/schema#', - 'title' => $model_definition->get_name(), - 'type' => 'object', + '$schema' => 'http://json-schema.org/schema#', + 'title' => $model_definition->get_name(), + 'type' => 'object', 'properties' => (array) apply_filters( 'mixtape_rest_api_schema_properties', $properties, $this->get_model_prototype() ), ); diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php index 6176100..2e77fff 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php @@ -46,12 +46,12 @@ class Zoninator_REST_Controller_Route { * Zoninator_REST_Controller_Route constructor. * * @param Zoninator_REST_Controller $controller A Controller. - * @param string $pattern Pattern. + * @param string $pattern Pattern. */ public function __construct( $controller, $pattern ) { - $this->controller = $controller; - $this->pattern = $pattern; - $this->actions = array(); + $this->controller = $controller; + $this->pattern = $pattern; + $this->actions = array(); $this->http_methods = explode( ', ', WP_REST_Server::ALLMETHODS ); } @@ -74,7 +74,7 @@ public function add_action( $action ) { * @return array */ public function as_array() { - $result = array(); + $result = array(); $result['pattern'] = $this->pattern; $result['actions'] = array(); foreach ( $this->actions as $action => $route_action ) { diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-settings.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-settings.php index 3194464..05ea322 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-settings.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-settings.php @@ -55,7 +55,7 @@ public function create_item( $request ) { * @return WP_REST_Response */ protected function create_or_update( $request ) { - $is_update = $request->get_method() !== 'POST'; + $is_update = $request->get_method() !== 'POST'; $model_to_update = $this->model_prototype->get_data_store()->get_entity( null ); if ( empty( $model_to_update ) ) { return $this->not_found( 'Model does not exist' ); @@ -79,7 +79,7 @@ protected function create_or_update( $request ) { } $model = $this->model_prototype->get_data_store()->get_entity( null ); - $dto = $this->prepare_dto( $model ); + $dto = $this->prepare_dto( $model ); return $is_update ? $this->ok( $dto ) : $this->created( $dto ); } diff --git a/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php b/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php index 08ea6bc..ba932dd 100644 --- a/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php +++ b/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php @@ -45,7 +45,7 @@ function __construct( $definition, $serializer ) { * @return array */ function raw_data_to_model_data( $data, $field_declarations ) { - $raw_data = array(); + $raw_data = array(); $post_array_keys = array_keys( $data ); foreach ( $field_declarations as $declaration ) { /** @@ -53,9 +53,9 @@ function raw_data_to_model_data( $data, $field_declarations ) { * * @var Zoninator_REST_Field_Declaration $declaration */ - $key = $declaration->get_name(); + $key = $declaration->get_name(); $mapping = $declaration->get_map_from(); - $value = null; + $value = null; if ( in_array( $key, $post_array_keys, true ) ) { // simplest case: we got a $key for this, so just map it. $value = $this->serializer->deserialize( $declaration, $data[ $key ] ); @@ -73,7 +73,7 @@ function raw_data_to_model_data( $data, $field_declarations ) { * Transform Model to raw data array * * @param Zoninator_REST_Interfaces_Model $model Model. - * @param null|string $field_type Type. + * @param null|string $field_type Type. * @return array */ function model_to_data( $model, $field_type = null ) { @@ -84,8 +84,8 @@ function model_to_data( $model, $field_type = null ) { * * @var Zoninator_REST_Field_Declaration $field_declaration */ - $what_to_map_to = $field_declaration->get_map_from(); - $value = $model->get( $field_declaration->get_name() ); + $what_to_map_to = $field_declaration->get_map_from(); + $value = $model->get( $field_declaration->get_name() ); $field_values_to_insert[ $what_to_map_to ] = $this->serializer->serialize( $field_declaration, $value ); } diff --git a/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php b/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php index 52dc711..4fa3f38 100644 --- a/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php +++ b/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php @@ -33,7 +33,7 @@ function __construct( $model_definition ) { * Deserialize * * @param Zoninator_REST_Field_Declaration $field_declaration Declaration. - * @param mixed $value Value. + * @param mixed $value Value. * @return mixed the deserialized value */ function deserialize( $field_declaration, $value ) { @@ -45,7 +45,7 @@ function deserialize( $field_declaration, $value ) { * Serialize * * @param Zoninator_REST_Field_Declaration $field_declaration Declaration. - * @param mixed $value Value. + * @param mixed $value Value. * @return mixed * @throws Zoninator_REST_Exception If call fails. */ diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php index 0ad89b1..bf84d9d 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php @@ -33,11 +33,11 @@ abstract class Zoninator_REST_Data_Store_Abstract implements Zoninator_REST_Inte * Zoninator_REST_Data_Store_Abstract constructor. * * @param null|Zoninator_REST_Model $model_prototype Def. - * @param array $args Args. + * @param array $args Args. */ public function __construct( $model_prototype = null, $args = array() ) { $this->type_serializers = array(); - $this->args = $args; + $this->args = $args; Zoninator_REST_Expect::is_a( $model_prototype, 'Zoninator_REST_Interfaces_Model' ); $this->set_model_factory( $model_prototype ); } diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php index f05fc19..54ff78c 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php @@ -24,7 +24,7 @@ class Zoninator_REST_Data_Store_CustomPostType extends Zoninator_REST_Data_Store * Mixtape_Data_Store_CustomPostType constructor. * * @param null|Zoninator_REST_Model_Definition $model_prototype Def. - * @param array $args Args. + * @param array $args Args. */ public function __construct( $model_prototype = null, $args = array() ) { $this->post_type = isset( $args['post_type'] ) ? $args['post_type'] : 'post'; @@ -39,11 +39,13 @@ public function __construct( $model_prototype = null, $args = array() ) { * @return Zoninator_REST_Model_Collection */ public function get_entities( $filter = null ) { - $query = new WP_Query( array( - 'post_type' => $this->post_type, - 'post_status' => 'any', - ) ); - $posts = $query->get_posts(); + $query = new WP_Query( + array( + 'post_type' => $this->post_type, + 'post_status' => 'any', + ) + ); + $posts = $query->get_posts(); $collection = array(); foreach ( $posts as $post ) { $collection[] = $this->create_from_post( $post ); @@ -75,8 +77,8 @@ public function get_entity( $id ) { */ private function create_from_post( $post ) { $field_declarations = $this->get_model_prototype()->get_fields(); - $raw_post_data = $post->to_array(); - $raw_meta_data = get_post_meta( $post->ID ); // assumes we are only ever adding one postmeta per key. + $raw_post_data = $post->to_array(); + $raw_meta_data = get_post_meta( $post->ID ); // assumes we are only ever adding one postmeta per key. $flattened_meta = array(); foreach ( $raw_meta_data as $key => $value_arr ) { @@ -84,24 +86,30 @@ private function create_from_post( $post ) { } $merged_data = array_merge( $raw_post_data, $flattened_meta ); - return $this->get_model_prototype()->create( $merged_data, array( - 'deserialize' => true, - ) ); + return $this->get_model_prototype()->create( + $merged_data, + array( + 'deserialize' => true, + ) + ); } /** * Delete * * @param Zoninator_REST_Interfaces_Model $model Model. - * @param array $args Args. + * @param array $args Args. * @return mixed */ public function delete( $model, $args = array() ) { $id = $model->get_id(); - $args = wp_parse_args( $args, array( - 'force_delete' => false, - ) ); + $args = wp_parse_args( + $args, + array( + 'force_delete' => false, + ) + ); do_action( 'mixtape_data_store_delete_model_before', $model, $id ); @@ -130,9 +138,9 @@ public function delete( $model, $args = array() ) { * @return mixed|WP_Error */ public function upsert( $model ) { - $id = $model->get_id(); - $updating = ! empty( $id ); - $fields = $model->serialize( Zoninator_REST_Field_Declaration::FIELD ); + $id = $model->get_id(); + $updating = ! empty( $id ); + $fields = $model->serialize( Zoninator_REST_Field_Declaration::FIELD ); $meta_fields = $model->serialize( Zoninator_REST_Field_Declaration::META ); if ( ! isset( $fields['post_type'] ) ) { $fields['post_type'] = $this->post_type; @@ -164,7 +172,7 @@ public function upsert( $model ) { 'mixtape-error-creating-meta', 'There was an error updating/creating an entity field', array( - 'field_key' => $meta_key, + 'field_key' => $meta_key, 'field_value' => $meta_value, ) ); diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php index 81a2281..d6fef95 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php @@ -39,7 +39,7 @@ public function get_entity( $id ) { * Delete * * @param Zoninator_REST_Interfaces_Model $model Model. - * @param array $args Args. + * @param array $args Args. * @return bool */ public function delete( $model, $args = array() ) { diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php index 5c4114b..de3c80a 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php @@ -25,7 +25,7 @@ class Zoninator_REST_Data_Store_Option extends Zoninator_REST_Data_Store_Abstrac * Zoninator_REST_Data_Store_Option constructor. * * @param Zoninator_REST_Model $model_prototype Def. - * @param array $args Args. + * @param array $args Args. */ public function __construct( $model_prototype, $args = array() ) { parent::__construct( $model_prototype, $args ); @@ -51,7 +51,7 @@ public function get_entities( $filter = null ) { */ public function get_entity( $id ) { $field_declarations = $this->get_model_prototype()->get_fields(); - $raw_data = array(); + $raw_data = array(); foreach ( $field_declarations as $field_declaration ) { /** * Field Declaration @@ -64,16 +64,19 @@ public function get_entity( $id ) { } } - return $this->get_model_prototype()->create( $raw_data, array( - 'deserialize' => true, - ) ); + return $this->get_model_prototype()->create( + $raw_data, + array( + 'deserialize' => true, + ) + ); } /** * Delete * * @param Zoninator_REST_Interfaces_Model $model Model. - * @param array $args Args. + * @param array $args Args. * @return mixed */ public function delete( $model, $args = array() ) { diff --git a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php index 50431d7..0fd121a 100644 --- a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php +++ b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php @@ -169,32 +169,32 @@ public function __construct( $args ) { throw new Zoninator_REST_Exception( 'every field should have a kind (one of ' . implode( ',', $this->field_kinds ) . ')' ); } - $this->name = $args['name']; - $this->description = $this->value_or_default( $args, 'description', '' ); + $this->name = $args['name']; + $this->description = $this->value_or_default( $args, 'description', '' ); - $this->kind = $args['kind']; - $this->type = $this->value_or_default( $args, 'type', Zoninator_REST_Type::any() ); - $this->choices = $this->value_or_default( $args, 'choices', null ); - $this->default_value = $this->value_or_default( $args, 'default_value' ); + $this->kind = $args['kind']; + $this->type = $this->value_or_default( $args, 'type', Zoninator_REST_Type::any() ); + $this->choices = $this->value_or_default( $args, 'choices', null ); + $this->default_value = $this->value_or_default( $args, 'default_value' ); - $this->map_from = $this->value_or_default( $args, 'map_from' ); - $this->data_transfer_name = $this->value_or_default( $args, 'data_transfer_name', $this->get_name() ); + $this->map_from = $this->value_or_default( $args, 'map_from' ); + $this->data_transfer_name = $this->value_or_default( $args, 'data_transfer_name', $this->get_name() ); - $this->primary = $this->value_or_default( $args, 'primary', false ); - $this->required = $this->value_or_default( $args, 'required', false ); - $this->supported_outputs = $this->value_or_default( $args, 'supported_outputs', array( 'json' ) ); + $this->primary = $this->value_or_default( $args, 'primary', false ); + $this->required = $this->value_or_default( $args, 'required', false ); + $this->supported_outputs = $this->value_or_default( $args, 'supported_outputs', array( 'json' ) ); - $this->sanitizer = $this->value_or_default( $args, 'sanitizer' ); - $this->validations = $this->value_or_default( $args, 'validations', array() ); + $this->sanitizer = $this->value_or_default( $args, 'sanitizer' ); + $this->validations = $this->value_or_default( $args, 'validations', array() ); - $this->serializer = $this->value_or_default( $args, 'serializer' ); - $this->deserializer = $this->value_or_default( $args, 'deserializer' ); + $this->serializer = $this->value_or_default( $args, 'serializer' ); + $this->deserializer = $this->value_or_default( $args, 'deserializer' ); - $this->before_get = $this->value_or_default( $args, 'before_get' ); - $this->before_set = $this->value_or_default( $args, 'before_set' ); + $this->before_get = $this->value_or_default( $args, 'before_get' ); + $this->before_set = $this->value_or_default( $args, 'before_set' ); - $this->reader = $this->value_or_default( $args, 'reader' ); - $this->updater = $this->value_or_default( $args, 'updater' ); + $this->reader = $this->value_or_default( $args, 'reader' ); + $this->updater = $this->value_or_default( $args, 'updater' ); } /** @@ -279,8 +279,8 @@ public function supports_output_type( $type ) { * @return array */ public function as_item_schema_property() { - $schema = $this->type->schema(); - $schema['context'] = array( 'view', 'edit' ); + $schema = $this->type->schema(); + $schema['context'] = array( 'view', 'edit' ); $schema['description'] = $this->get_description(); if ( $this->get_choices() ) { diff --git a/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php b/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php index 8fc4825..1f70ea0 100644 --- a/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php +++ b/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php @@ -133,7 +133,6 @@ public function with_deserializer( $deserializer ) { */ public function with_required( $required = true ) { return $this->with( 'required', $required ); - } /** diff --git a/lib/zoninator_rest/interfaces/data/class-zoninator-rest-interfaces-data-store.php b/lib/zoninator_rest/interfaces/data/class-zoninator-rest-interfaces-data-store.php index 21dce65..a6b4601 100644 --- a/lib/zoninator_rest/interfaces/data/class-zoninator-rest-interfaces-data-store.php +++ b/lib/zoninator_rest/interfaces/data/class-zoninator-rest-interfaces-data-store.php @@ -36,7 +36,7 @@ public function get_entity( $id ); * Delete a Model * * @param Zoninator_REST_Interfaces_Model $model The model to delete. - * @param array $args Args. + * @param array $args Args. * @return mixed */ public function delete( $model, $args = array() ); diff --git a/lib/zoninator_rest/interfaces/model/class-zoninator-rest-interfaces-model-declaration.php b/lib/zoninator_rest/interfaces/model/class-zoninator-rest-interfaces-model-declaration.php index 83b3084..c5b4917 100644 --- a/lib/zoninator_rest/interfaces/model/class-zoninator-rest-interfaces-model-declaration.php +++ b/lib/zoninator_rest/interfaces/model/class-zoninator-rest-interfaces-model-declaration.php @@ -49,7 +49,7 @@ function declare_fields( $environment ); * @param array $args The args. * @return mixed */ - function call( $method, $args = array()); + function call( $method, $args = array() ); /** * Get this model's unique identifier @@ -63,7 +63,7 @@ function get_id( $model ); * Set this model's unique identifier * * @param Zoninator_REST_Interfaces_Model $model The model. - * @param mixed $id The id. + * @param mixed $id The id. * * @return Zoninator_REST_Interfaces_Model The model. */ @@ -75,5 +75,4 @@ function set_id( $model, $id ); * @return string This declaration's name. */ function get_name(); - } diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php b/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php index c29dd74..6393073 100644 --- a/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php +++ b/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php @@ -68,7 +68,7 @@ function get_id( $model ) { * Set the id * * @param Zoninator_REST_Interfaces_Model $model The model. - * @param mixed $new_id The new id. + * @param mixed $new_id The new id. * * @return mixed|null */ diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php b/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php index 0bb2ff9..d2065f2 100644 --- a/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php +++ b/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php @@ -63,21 +63,21 @@ class Zoninator_REST_Model_Definition implements Zoninator_REST_Interfaces_Permi /** * Mixtape_Model_Definition constructor. * - * @param Zoninator_REST_Environment $environment The Environment. - * @param Zoninator_REST_Interfaces_Model_Declaration $model_declaration Declaration. + * @param Zoninator_REST_Environment $environment The Environment. + * @param Zoninator_REST_Interfaces_Model_Declaration $model_declaration Declaration. * @param Zoninator_REST_Interfaces_Data_Store|Zoninator_REST_Data_Store_Builder $data_store Store. - * @param Zoninator_REST_Interfaces_Permissions_Provider $permissions_provider Provider. + * @param Zoninator_REST_Interfaces_Permissions_Provider $permissions_provider Provider. * * @throws Zoninator_REST_Exception Throws if wrong types or null args provided. */ function __construct( $environment, $model_declaration, $data_store, $permissions_provider ) { - Zoninator_REST_Expect::that( null !== $environment , '$environment cannot be null' ); - Zoninator_REST_Expect::that( null !== $model_declaration , '$model_declaration cannot be null' ); - Zoninator_REST_Expect::that( null !== $data_store , '$data_store cannot be null' ); + Zoninator_REST_Expect::that( null !== $environment, '$environment cannot be null' ); + Zoninator_REST_Expect::that( null !== $model_declaration, '$model_declaration cannot be null' ); + Zoninator_REST_Expect::that( null !== $data_store, '$data_store cannot be null' ); Zoninator_REST_Expect::that( null !== $permissions_provider, '$permissions_provider cannot be null' ); // Fail if provided with inappropriate types. - Zoninator_REST_Expect::is_a( $environment , 'Zoninator_REST_Environment' ); - Zoninator_REST_Expect::is_a( $model_declaration , 'Zoninator_REST_Interfaces_Model_Declaration' ); + Zoninator_REST_Expect::is_a( $environment, 'Zoninator_REST_Environment' ); + Zoninator_REST_Expect::is_a( $model_declaration, 'Zoninator_REST_Interfaces_Model_Declaration' ); Zoninator_REST_Expect::is_a( $permissions_provider, 'Zoninator_REST_Interfaces_Permissions_Provider' ); $this->field_declarations = null; @@ -195,8 +195,8 @@ function create_instance( $data ) { * Note: Values change in place. * * @param Zoninator_REST_Interfaces_Model $model The model. - * @param array $data The data (key-value assumed). - * @param bool $updating Is this an update?. + * @param array $data The data (key-value assumed). + * @param bool $updating Is this an update?. * * @return Zoninator_REST_Interfaces_Model|WP_Error * @throws Zoninator_REST_Exception Throws. @@ -260,7 +260,7 @@ function get_dto_field_mappings() { function model_to_dto( $model ) { $result = array(); foreach ( $this->get_dto_field_mappings() as $mapping_name => $field_name ) { - $value = $model->get( $field_name ); + $value = $model->get( $field_name ); $result[ $mapping_name ] = $value; } @@ -296,7 +296,7 @@ public function permissions_check( $request, $action ) { */ private function map_data( $data, $updating = false ) { $request_data = array(); - $fields = $this->get_field_declarations(); + $fields = $this->get_field_declarations(); foreach ( $fields as $field ) { /** * Field @@ -306,10 +306,10 @@ private function map_data( $data, $updating = false ) { if ( $field->is_kind( Zoninator_REST_Field_Declaration::DERIVED ) ) { continue; } - $dto_name = $field->get_data_transfer_name(); + $dto_name = $field->get_data_transfer_name(); $field_name = $field->get_name(); if ( isset( $data[ $dto_name ] ) && ! ( $updating && $field->is_primary() ) ) { - $value = $data[ $dto_name ]; + $value = $data[ $dto_name ]; $request_data[ $field_name ] = $value; } } @@ -331,7 +331,7 @@ private function initialize_field_map( $declared_field_builders ) { * * @var Zoninator_REST_Field_Declaration $field Field Builder. */ - $field = $field_builder->build(); + $field = $field_builder->build(); $fields[ $field->get_name() ] = $field; } return $fields; diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php index f1c0fb1..4d727f4 100644 --- a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php +++ b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php @@ -40,9 +40,9 @@ protected function default_for_attribute( $field_data, $attribute ) { /** * On Field Setup * - * @param string $field_name Name. + * @param string $field_name Name. * @param Zoninator_REST_Field_Declaration_Builder $field_builder Builder. - * @param array $field_data Data. + * @param array $field_data Data. * @param Zoninator_REST_Environment $env Env. * @return void */ @@ -55,16 +55,16 @@ protected function on_field_setup( $field_name, $field_builder, $field_data, $en * @return array */ public function declare_fields() { - $env = $this->get_environment(); + $env = $this->get_environment(); $settings_per_group = $this->get_settings(); - $fields = array(); + $fields = array(); foreach ( $settings_per_group as $group_name => $group_data ) { $group_fields = $group_data[1]; foreach ( $group_fields as $field_data ) { $field_builder = $this->field_declaration_builder_from_data( $env, $field_data ); - $fields[] = $field_builder; + $fields[] = $field_builder; } } return $fields; @@ -113,18 +113,18 @@ public function set_id( $new_id ) { * Build declarations from array * * @param Zoninator_REST_Environment $env Environment. - * @param array $field_data Data. + * @param array $field_data Data. * @return Zoninator_REST_Field_Declaration_Builder */ private function field_declaration_builder_from_data( $env, $field_data ) { - $field_name = $field_data['name']; + $field_name = $field_data['name']; $field_builder = $env->field( $field_name ); $default_value = isset( $field_data['std'] ) ? $field_data['std'] : $this->default_for_attribute( $field_data, 'std' ); - $label = isset( $field_data['label'] ) ? $field_data['label'] : $field_name; - $description = isset( $field_data['desc'] ) ? $field_data['desc'] : $label; - $setting_type = isset( $field_data['type'] ) ? $field_data['type'] : null; - $choices = isset( $field_data['options'] ) ? array_keys( $field_data['options'] ) : null; - $field_type = 'string'; + $label = isset( $field_data['label'] ) ? $field_data['label'] : $field_name; + $description = isset( $field_data['desc'] ) ? $field_data['desc'] : $label; + $setting_type = isset( $field_data['type'] ) ? $field_data['type'] : null; + $choices = isset( $field_data['options'] ) ? array_keys( $field_data['options'] ) : null; + $field_type = 'string'; if ( 'checkbox' === $setting_type ) { $field_type = 'boolean'; @@ -135,7 +135,6 @@ private function field_declaration_builder_from_data( $env, $field_data ) { $field_builder ->with_serializer( array( $this, 'bool_to_bit' ) ) ->with_deserializer( array( $this, 'bit_to_bool' ) ); - } elseif ( 'select' === $setting_type ) { $field_type = 'string'; } else { diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php b/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php index 9e83f1a..afa83a7 100644 --- a/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php +++ b/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php @@ -35,7 +35,7 @@ class Zoninator_REST_Model_ValidationData { /** * Mixtape_Model_ValidationData constructor. * - * @param mixed $value The value. + * @param mixed $value The value. * @param Zoninator_REST_Interfaces_Model $model The Model. * @param Zoninator_REST_Field_Declaration $field The Field. */ diff --git a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php index bdfa3d6..7e197d9 100644 --- a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php +++ b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php @@ -13,8 +13,7 @@ * Class Mixtape_Model_Declaration_Settings * Represents a single setting field */ -class Zoninator_REST_Model_Declaration_Settings extends Zoninator_REST_Model_Declaration - implements Zoninator_REST_Interfaces_Permissions_Provider { +class Zoninator_REST_Model_Declaration_Settings extends Zoninator_REST_Model_Declaration implements Zoninator_REST_Interfaces_Permissions_Provider { /** * Get Settings @@ -39,9 +38,9 @@ protected function default_for_attribute( $field_data, $attribute ) { /** * On Field Setup * - * @param string $field_name Name. + * @param string $field_name Name. * @param Zoninator_REST_Field_Declaration_Builder $field_builder Builder. - * @param array $field_data Data. + * @param array $field_data Data. * @param Zoninator_REST_Environment $env Env. * @return void */ @@ -56,14 +55,14 @@ protected function on_field_setup( $field_name, $field_builder, $field_data, $en */ function declare_fields( $env ) { $settings_per_group = $this->get_settings(); - $fields = array(); + $fields = array(); foreach ( $settings_per_group as $group_name => $group_data ) { $group_fields = $group_data[1]; foreach ( $group_fields as $field_data ) { $field_builder = $this->field_declaration_builder_from_data( $env, $field_data ); - $fields[] = $field_builder; + $fields[] = $field_builder; } } return $fields; @@ -103,7 +102,7 @@ function get_id( $model ) { * Set ID * * @param Zoninator_REST_Interfaces_Model $model Model. - * @param mixed $new_id New ID. + * @param mixed $new_id New ID. * @return Zoninator_REST_Interfaces_Model $this */ function set_id( $model, $new_id ) { @@ -114,18 +113,18 @@ function set_id( $model, $new_id ) { * Build declarations from array * * @param Zoninator_REST_Environment $env Environment. - * @param array $field_data Data. + * @param array $field_data Data. * @return Zoninator_REST_Field_Declaration_Builder */ private function field_declaration_builder_from_data( $env, $field_data ) { - $field_name = $field_data['name']; + $field_name = $field_data['name']; $field_builder = $env->field( $field_name ); $default_value = isset( $field_data['std'] ) ? $field_data['std'] : $this->default_for_attribute( $field_data, 'std' ); - $label = isset( $field_data['label'] ) ? $field_data['label'] : $field_name; - $description = isset( $field_data['desc'] ) ? $field_data['desc'] : $label; - $setting_type = isset( $field_data['type'] ) ? $field_data['type'] : null; - $choices = isset( $field_data['options'] ) ? array_keys( $field_data['options'] ) : null; - $field_type = 'string'; + $label = isset( $field_data['label'] ) ? $field_data['label'] : $field_name; + $description = isset( $field_data['desc'] ) ? $field_data['desc'] : $label; + $setting_type = isset( $field_data['type'] ) ? $field_data['type'] : null; + $choices = isset( $field_data['options'] ) ? array_keys( $field_data['options'] ) : null; + $field_type = 'string'; if ( 'checkbox' === $setting_type ) { $field_type = 'boolean'; @@ -136,7 +135,6 @@ private function field_declaration_builder_from_data( $env, $field_data ) { $field_builder ->with_serializer( array( $this, 'bool_to_bit' ) ) ->with_deserializer( array( $this, 'bit_to_bool' ) ); - } elseif ( 'select' === $setting_type ) { $field_type = 'string'; } else { diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php b/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php index 3712378..5dde989 100644 --- a/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php +++ b/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php @@ -69,7 +69,7 @@ public function sanitize( $value ) { * Schema */ function schema() { - $schema = parent::schema(); + $schema = parent::schema(); $schema['type'] = array_unique( array_merge( $schema['type'], array( 'null' ) ) ); } } diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php b/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php index 12cdfca..f081045 100644 --- a/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php +++ b/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php @@ -33,7 +33,7 @@ class Zoninator_REST_Type_Registry { /** * Define a new type * - * @param string $identifier The Identifier. + * @param string $identifier The Identifier. * @param Zoninator_REST_Interfaces_Type $instance The type instance. * * @return Zoninator_REST_Type_Registry $this @@ -61,7 +61,6 @@ function definition( $type ) { // maybe lazy-register missing compound type. $parts = explode( ':', $type ); if ( count( $parts ) > 1 ) { - $container_type = $parts[0]; if ( ! in_array( $container_type, $this->container_types, true ) ) { throw new Zoninator_REST_Exception( $container_type . ' is not a known container type' ); @@ -110,16 +109,21 @@ public function initialize( $environment ) { return; } - $this->types = apply_filters( 'mixtape_type_registry_register_types', array( - 'any' => new Zoninator_REST_Type( 'any' ), - 'string' => new Zoninator_REST_Type_String(), - 'integer' => new Zoninator_REST_Type_Integer(), - 'int' => new Zoninator_REST_Type_Integer(), - 'uint' => new Zoninator_REST_Type_Integer( true ), - 'number' => new Zoninator_REST_Type_Number(), - 'float' => new Zoninator_REST_Type_Number(), - 'boolean' => new Zoninator_REST_Type_Boolean(), - 'array' => new Zoninator_REST_Type_Array(), - ), $this, $environment ); + $this->types = apply_filters( + 'mixtape_type_registry_register_types', + array( + 'any' => new Zoninator_REST_Type( 'any' ), + 'string' => new Zoninator_REST_Type_String(), + 'integer' => new Zoninator_REST_Type_Integer(), + 'int' => new Zoninator_REST_Type_Integer(), + 'uint' => new Zoninator_REST_Type_Integer( true ), + 'number' => new Zoninator_REST_Type_Number(), + 'float' => new Zoninator_REST_Type_Number(), + 'boolean' => new Zoninator_REST_Type_Boolean(), + 'array' => new Zoninator_REST_Type_Array(), + ), + $this, + $environment + ); } } diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php b/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php index 34b84ab..2c93b04 100644 --- a/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php +++ b/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php @@ -63,8 +63,8 @@ public function cast( $value ) { * @return array */ function schema() { - $schema = parent::schema(); - $schema['type'] = 'array'; + $schema = parent::schema(); + $schema['type'] = 'array'; $schema['items'] = $this->item_type_definition->schema(); return $schema; } diff --git a/widget.zone-posts.php b/widget.zone-posts.php index cee118c..2bf1357 100644 --- a/widget.zone-posts.php +++ b/widget.zone-posts.php @@ -7,8 +7,8 @@ class Zoninator_ZonePosts_Widget extends WP_Widget { function __construct() { $widget_ops = array( - 'classname' => 'widget-zone-posts', - 'description' => __( 'Use this widget to display a list of posts from any zone.', 'zoninator' ) + 'classname' => 'widget-zone-posts', + 'description' => __( 'Use this widget to display a list of posts from any zone.', 'zoninator' ), ); $this->alt_option_name = 'widget_zone_posts'; @@ -25,10 +25,11 @@ function __construct() { function widget( $args, $instance ) { $cache_key = 'widget-zone-posts'; - $cache = wp_cache_get( $cache_key, 'widget' ); + $cache = wp_cache_get( $cache_key, 'widget' ); - if ( ! is_array( $cache ) ) + if ( ! is_array( $cache ) ) { $cache = array(); + } if ( isset( $cache[ $args['widget_id'] ] ) ) { echo $cache[ $args['widget_id'] ]; @@ -39,16 +40,19 @@ function widget( $args, $instance ) { $zone_id = $instance['zone_id'] ? $instance['zone_id'] : 0; $show_description = $instance['show_description'] ? 1 : 0; - if ( ! $zone_id ) + if ( ! $zone_id ) { return; + } $zone = z_get_zone( $zone_id ); - if ( ! $zone ) + if ( ! $zone ) { return; + } $posts = z_get_posts_in_zone( $zone_id ); - if ( empty( $posts ) ) + if ( empty( $posts ) ) { return; + } ?> @@ -82,14 +86,21 @@ function widget( $args, $instance ) { } function update( $new_instance, $old_instance ) { - $instance = $old_instance; - $new_instance = wp_parse_args( (array) $new_instance, array( 'zone_id' => 0, 'show_description' => 0 ) ); + $instance = $old_instance; + $new_instance = wp_parse_args( + (array) $new_instance, + array( + 'zone_id' => 0, + 'show_description' => 0, + ) + ); $instance['zone_id'] = absint( $new_instance['zone_id'] ); $instance['show_description'] = $new_instance['show_description'] ? 1 : 0; $this->flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); - if ( isset( $alloptions['widget-zone-posts'] ) ) + if ( isset( $alloptions['widget-zone-posts'] ) ) { delete_option( 'widget-zone-posts' ); + } return $instance; } @@ -140,6 +151,6 @@ function form( $instance ) {

- '' +if ( ! class_exists( 'Zoninator' ) ) : + define( 'ZONINATOR_VERSION', '0.10.0' ); + define( 'ZONINATOR_PATH', __DIR__ ); + define( 'ZONINATOR_URL', trailingslashit( plugins_url( '', __FILE__ ) ) ); + + require_once ZONINATOR_PATH . '/functions.php'; + require_once ZONINATOR_PATH . '/widget.zone-posts.php'; + + class Zoninator { + + var $key = 'zoninator'; + var $zone_taxonomy = 'zoninator_zones'; + var $zone_term_prefix = 'zone-'; + var $zone_meta_prefix = '_zoninator_order_'; + var $zone_nonce_prefix = 'zone-nonce'; + var $zone_ajax_nonce_action = 'ajax-action'; + var $zone_lock_period = 30; // number of seconds a lock is valid for + var $zone_max_lock_period = 600; // max number of seconds for all locks in a session + var $post_types = null; + var $zone_detail_defaults = array( + 'description' => '', // Add additional properties here! - ); - var $zone_messages = null; - var $posts_per_page = 10; - /** - * @var Zoninator_Api - */ - public $rest_api = null; - /** - * @var array|string[] Default post types that support zones. - */ - public $default_post_types = array( 'post' ); - - function __construct() { - add_action( 'init', array( $this, 'init' ), 99 ); // init later after other post types have been registered + ); + var $zone_messages = null; + var $posts_per_page = 10; + /** + * @var Zoninator_Api + */ + public $rest_api = null; + /** + * @var array|string[] Default post types that support zones. + */ + public $default_post_types = array( 'post' ); - add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); + function __construct() { + add_action( 'init', array( $this, 'init' ), 99 ); // init later after other post types have been registered - add_action( 'widgets_init', array( $this, 'widgets_init' ) ); + add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); - add_action( 'init', array( $this, 'add_zone_feed' ) ); + add_action( 'widgets_init', array( $this, 'widgets_init' ) ); - add_action( 'template_redirect', array( $this, 'do_zoninator_feeds' ) ); + add_action( 'init', array( $this, 'add_zone_feed' ) ); - add_action( 'split_shared_term', array( $this, 'split_shared_term' ), 10, 4 ); + add_action( 'template_redirect', array( $this, 'do_zoninator_feeds' ) ); - $this->maybe_add_rest_api(); - } + add_action( 'split_shared_term', array( $this, 'split_shared_term' ), 10, 4 ); - public function maybe_add_rest_api() { - global $wp_version; - if ( version_compare( $wp_version, '4.7', '<' ) ) { - return false; + $this->maybe_add_rest_api(); } - include_once 'includes/class-zoninator-api.php'; - $this->rest_api = new Zoninator_Api( $this ); - } - - function add_zone_feed() { - add_rewrite_tag( '%' . $this->zone_taxonomy . '%', '([^&]+)' ); - add_rewrite_rule( '^zones/([^/]+)/feed.json/?$', 'index.php?' . $this->zone_taxonomy . '=$matches[1]', 'top' ); - } - - function init() { - $this->zone_messages = array( - 'insert-success' => __( 'The zone was successfully created.', 'zoninator' ), - 'update-success' => __( 'The zone was successfully updated.', 'zoninator' ), - 'delete-success' => __( 'The zone was successfully deleted.', 'zoninator' ), - 'error-general' => __( 'Sorry, something went wrong! Please try again?', 'zoninator' ), - 'error-zone-lock' => __( 'Sorry, this zone is in use by %s and is currently locked. Please try again later.', 'zoninator' ), - 'error-zone-lock-max' => __( 'Sorry, you have reached the maximum idle limit and will now be redirected to the Dashboard.', 'zoninator' ), - ); - - $this->zone_lock_period = apply_filters( 'zoninator_zone_lock_period', $this->zone_lock_period ); - $this->zone_max_lock_period = apply_filters( 'zoninator_zone_max_lock_period', $this->zone_max_lock_period ); - $this->posts_per_page = apply_filters( 'zoninator_posts_per_page', $this->posts_per_page ); - - do_action( 'zoninator_pre_init' ); - - // Default post type support - foreach( $this->default_post_types as $post_type ) - add_post_type_support( $post_type, $this->zone_taxonomy ); - - // Register taxonomy - if( ! taxonomy_exists( $this->zone_taxonomy ) ) { - register_taxonomy( $this->zone_taxonomy, $this->get_supported_post_types(), array( - 'label' => __( 'Zones', 'zoninator' ), - 'hierarchical' => false, - 'query_var' => false, - 'rewrite' => false, - 'public' => false, + public function maybe_add_rest_api() { + global $wp_version; + if ( version_compare( $wp_version, '4.7', '<' ) ) { + return false; + } - ) ); + include_once 'includes/class-zoninator-api.php'; + $this->rest_api = new Zoninator_Api( $this ); } - add_action( 'admin_init', array( $this, 'admin_controller' ) ); - add_action( 'admin_init', array( $this, 'admin_init' ) ); - - add_action( 'admin_menu', array( $this, 'admin_page_init' ) ); - - # Add default advanced search fields - add_action( 'zoninator_advanced_search_fields', array( $this, 'zone_advanced_search_cat_filter' ) ); - add_action( 'zoninator_advanced_search_fields', array( $this, 'zone_advanced_search_date_filter' ), 20 ); - - do_action( 'zoninator_post_init' ); - } - - public function load_textdomain() { - load_plugin_textdomain( 'zoninator', false, basename( ZONINATOR_PATH ) . '/language' ); - } + function add_zone_feed() { + add_rewrite_tag( '%' . $this->zone_taxonomy . '%', '([^&]+)' ); + add_rewrite_rule( '^zones/([^/]+)/feed.json/?$', 'index.php?' . $this->zone_taxonomy . '=$matches[1]', 'top' ); + } - function widgets_init() { - register_widget( 'Zoninator_ZonePosts_Widget' ); - } + function init() { + $this->zone_messages = array( + 'insert-success' => __( 'The zone was successfully created.', 'zoninator' ), + 'update-success' => __( 'The zone was successfully updated.', 'zoninator' ), + 'delete-success' => __( 'The zone was successfully deleted.', 'zoninator' ), + 'error-general' => __( 'Sorry, something went wrong! Please try again?', 'zoninator' ), + 'error-zone-lock' => __( 'Sorry, this zone is in use by %s and is currently locked. Please try again later.', 'zoninator' ), + 'error-zone-lock-max' => __( 'Sorry, you have reached the maximum idle limit and will now be redirected to the Dashboard.', 'zoninator' ), + ); - // Add necessary AJAX actions - function admin_ajax_init( ) { - add_action( 'wp_ajax_zoninator_reorder_posts', array( $this, 'ajax_reorder_posts' ) ); - add_action( 'wp_ajax_zoninator_add_post', array( $this, 'ajax_add_post' ) ); - add_action( 'wp_ajax_zoninator_remove_post', array( $this, 'ajax_remove_post' ) ); - add_action( 'wp_ajax_zoninator_search_posts', array( $this, 'ajax_search_posts' ) ); - add_action( 'wp_ajax_zoninator_update_lock', array( $this, 'ajax_update_lock' ) ); - add_action( 'wp_ajax_zoninator_update_recent', array( $this, 'ajax_recent_posts' ) ); + $this->zone_lock_period = apply_filters( 'zoninator_zone_lock_period', $this->zone_lock_period ); + $this->zone_max_lock_period = apply_filters( 'zoninator_zone_max_lock_period', $this->zone_max_lock_period ); + $this->posts_per_page = apply_filters( 'zoninator_posts_per_page', $this->posts_per_page ); - } + do_action( 'zoninator_pre_init' ); - function admin_init() { + // Default post type support + foreach ( $this->default_post_types as $post_type ) { + add_post_type_support( $post_type, $this->zone_taxonomy ); + } - $this->admin_ajax_init(); + // Register taxonomy + if ( ! taxonomy_exists( $this->zone_taxonomy ) ) { + register_taxonomy( + $this->zone_taxonomy, + $this->get_supported_post_types(), + array( + 'label' => __( 'Zones', 'zoninator' ), + 'hierarchical' => false, + 'query_var' => false, + 'rewrite' => false, + 'public' => false, - // Enqueue Scripts and Styles - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ) ); - } + ) + ); + } - function admin_page_init() { - // Set up page - add_menu_page( __( 'Zoninator', 'zoninator' ), __( 'Zones', 'zoninator' ), $this->_get_manage_zones_cap(), $this->key, array( $this, 'admin_page' ), '', 11 ); - } + add_action( 'admin_init', array( $this, 'admin_controller' ) ); + add_action( 'admin_init', array( $this, 'admin_init' ) ); - function admin_enqueue_scripts() { - if( $this->is_zoninator_page() ) { - wp_enqueue_script( 'zoninator-js', ZONINATOR_URL . 'js/zoninator.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-position', 'jquery-ui-sortable', 'jquery-ui-autocomplete' ), ZONINATOR_VERSION, true ); - - $options = array( - 'baseUrl' => $this->_get_zone_page_url(), - 'adminUrl' => admin_url(), - 'ajaxNonceAction' => $this->_get_nonce_key( $this->zone_ajax_nonce_action ), - 'errorGeneral' => $this->_get_message( 'error-general' ), - 'errorZoneLock' => sprintf( $this->_get_message( 'error-zone-lock' ), __( 'another user', 'zoninator' ) ), - 'errorZoneLockMax' => $this->_get_message( 'error-zone-lock-max' ), - 'zoneLockPeriod' => $this->zone_lock_period, - 'zoneLockPeriodMax' => $this->zone_max_lock_period, - ); - wp_localize_script( 'zoninator-js', 'zoninatorOptions', $options ); + add_action( 'admin_menu', array( $this, 'admin_page_init' ) ); - // For mobile support - // http://github.com/furf/jquery-ui-touch-punch - wp_enqueue_script( 'jquery-ui-touch-punch', ZONINATOR_URL . 'js/jquery.ui.touch-punch.min.js', array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse' ) ); + // Add default advanced search fields + add_action( 'zoninator_advanced_search_fields', array( $this, 'zone_advanced_search_cat_filter' ) ); + add_action( 'zoninator_advanced_search_fields', array( $this, 'zone_advanced_search_date_filter' ), 20 ); + do_action( 'zoninator_post_init' ); } - } - function admin_enqueue_styles() { - if( $this->is_zoninator_page() ) { - wp_enqueue_style( 'zoninator-jquery-ui', ZONINATOR_URL . 'css/jquery-ui/smoothness/jquery-ui-zoninator.css', false, ZONINATOR_VERSION, 'all' ); - wp_enqueue_style( 'zoninator-styles', ZONINATOR_URL . 'css/zoninator.css', false, ZONINATOR_VERSION, 'all' ); + public function load_textdomain() { + load_plugin_textdomain( 'zoninator', false, basename( ZONINATOR_PATH ) . '/language' ); } - } - function admin_controller() { - if( $this->is_zoninator_page() ) { - $action = $this->_get_request_var( 'action' ); + function widgets_init() { + register_widget( 'Zoninator_ZonePosts_Widget' ); + } - switch( $action ) { + // Add necessary AJAX actions + function admin_ajax_init() { + add_action( 'wp_ajax_zoninator_reorder_posts', array( $this, 'ajax_reorder_posts' ) ); + add_action( 'wp_ajax_zoninator_add_post', array( $this, 'ajax_add_post' ) ); + add_action( 'wp_ajax_zoninator_remove_post', array( $this, 'ajax_remove_post' ) ); + add_action( 'wp_ajax_zoninator_search_posts', array( $this, 'ajax_search_posts' ) ); + add_action( 'wp_ajax_zoninator_update_lock', array( $this, 'ajax_update_lock' ) ); + add_action( 'wp_ajax_zoninator_update_recent', array( $this, 'ajax_recent_posts' ) ); + } - case 'insert': - case 'update': - $zone_id = $this->_get_post_var( 'zone_id', 0, 'absint' ); + function admin_init() { - $this->verify_nonce( $action ); - $this->verify_access( $action, $zone_id ); + $this->admin_ajax_init(); - $name = $this->_get_post_var( 'name', '', array( $this, '_sanitize_value' ) ); - $slug = $this->_get_post_var( 'slug', sanitize_title( $name ) ); - $details = array( - 'description' => $this->_get_post_var( 'description', '', array( $this, '_sanitize_value' ) ) - ); + // Enqueue Scripts and Styles + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ) ); + } - // TODO: handle additional properties - if( $zone_id ) { - $result = $this->update_zone( $zone_id, array( - 'name' => $name, - 'slug' => $slug, - 'details' => $details - ) ); + function admin_page_init() { + // Set up page + add_menu_page( __( 'Zoninator', 'zoninator' ), __( 'Zones', 'zoninator' ), $this->_get_manage_zones_cap(), $this->key, array( $this, 'admin_page' ), '', 11 ); + } - } else { - $result = $this->insert_zone( $slug, $name, $details ); - } + function admin_enqueue_scripts() { + if ( $this->is_zoninator_page() ) { + wp_enqueue_script( 'zoninator-js', ZONINATOR_URL . 'js/zoninator.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-position', 'jquery-ui-sortable', 'jquery-ui-autocomplete' ), ZONINATOR_VERSION, true ); + + $options = array( + 'baseUrl' => $this->_get_zone_page_url(), + 'adminUrl' => admin_url(), + 'ajaxNonceAction' => $this->_get_nonce_key( $this->zone_ajax_nonce_action ), + 'errorGeneral' => $this->_get_message( 'error-general' ), + 'errorZoneLock' => sprintf( $this->_get_message( 'error-zone-lock' ), __( 'another user', 'zoninator' ) ), + 'errorZoneLockMax' => $this->_get_message( 'error-zone-lock-max' ), + 'zoneLockPeriod' => $this->zone_lock_period, + 'zoneLockPeriodMax' => $this->zone_max_lock_period, + ); + wp_localize_script( 'zoninator-js', 'zoninatorOptions', $options ); + + // For mobile support + // http://github.com/furf/jquery-ui-touch-punch + wp_enqueue_script( 'jquery-ui-touch-punch', ZONINATOR_URL . 'js/jquery.ui.touch-punch.min.js', array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse' ) ); + } + } - if( is_wp_error( $result ) ) { - wp_redirect( add_query_arg( 'message', 'error-general' ) ); - exit; - } else { - if( ! $zone_id && isset( $result['term_id'] ) ) - $zone_id = $result['term_id']; + function admin_enqueue_styles() { + if ( $this->is_zoninator_page() ) { + wp_enqueue_style( 'zoninator-jquery-ui', ZONINATOR_URL . 'css/jquery-ui/smoothness/jquery-ui-zoninator.css', false, ZONINATOR_VERSION, 'all' ); + wp_enqueue_style( 'zoninator-styles', ZONINATOR_URL . 'css/zoninator.css', false, ZONINATOR_VERSION, 'all' ); + } + } - // Redirect with success message - $message = sprintf( '%s-success', $action ); - wp_redirect( $this->_get_zone_page_url( array( 'action' => 'edit', 'zone_id' => $zone_id, 'message' => $message ) ) ); + function admin_controller() { + if ( $this->is_zoninator_page() ) { + $action = $this->_get_request_var( 'action' ); + + switch ( $action ) { + case 'insert': + case 'update': + $zone_id = $this->_get_post_var( 'zone_id', 0, 'absint' ); + + $this->verify_nonce( $action ); + $this->verify_access( $action, $zone_id ); + + $name = $this->_get_post_var( 'name', '', array( $this, '_sanitize_value' ) ); + $slug = $this->_get_post_var( 'slug', sanitize_title( $name ) ); + $details = array( + 'description' => $this->_get_post_var( 'description', '', array( $this, '_sanitize_value' ) ), + ); + + // TODO: handle additional properties + if ( $zone_id ) { + $result = $this->update_zone( + $zone_id, + array( + 'name' => $name, + 'slug' => $slug, + 'details' => $details, + ) + ); + } else { + $result = $this->insert_zone( $slug, $name, $details ); + } + + if ( is_wp_error( $result ) ) { + wp_redirect( add_query_arg( 'message', 'error-general' ) ); + exit; + } else { + if ( ! $zone_id && isset( $result['term_id'] ) ) { + $zone_id = $result['term_id']; + } + + // Redirect with success message + $message = sprintf( '%s-success', $action ); + wp_redirect( + $this->_get_zone_page_url( + array( + 'action' => 'edit', + 'zone_id' => $zone_id, + 'message' => $message, + ) + ) + ); + exit; + } + break; + + case 'delete': + $zone_id = $this->_get_request_var( 'zone_id', 0, 'absint' ); + + $this->verify_nonce( $action ); + $this->verify_access( $action, $zone_id ); + + if ( $zone_id ) { + $result = $this->delete_zone( $zone_id ); + } + + if ( is_wp_error( $result ) ) { + $redirect_args = array( 'error' => $result->get_error_messages() ); + } else { + $redirect_args = array( 'message' => 'delete-success' ); + } + + wp_redirect( $this->_get_zone_page_url( $redirect_args ) ); exit; - } - break; - - case 'delete': - $zone_id = $this->_get_request_var( 'zone_id', 0, 'absint' ); - - $this->verify_nonce( $action ); - $this->verify_access( $action, $zone_id ); - - if( $zone_id ) { - $result = $this->delete_zone( $zone_id ); - } - - if( is_wp_error( $result ) ) { - $redirect_args = array( 'error' => $result->get_error_messages() ); - } else { - $redirect_args = array( 'message' => 'delete-success' ); - } - - wp_redirect( $this->_get_zone_page_url( $redirect_args ) ); - exit; + } } } - } - function admin_page() { - global $zoninator_admin_page; + function admin_page() { + global $zoninator_admin_page; - $view = $this->_get_value_or_default( 'view', $zoninator_admin_page, 'edit.php' ); - $view = sprintf( '%s/views/%s', ZONINATOR_PATH, $view ); - $title = __( 'Zones', 'zoninator' ); + $view = $this->_get_value_or_default( 'view', $zoninator_admin_page, 'edit.php' ); + $view = sprintf( '%s/views/%s', ZONINATOR_PATH, $view ); + $title = __( 'Zones', 'zoninator' ); - $zones = $this->get_zones( apply_filters( 'zoninator_admin_page_get_zones_args', array() ) ); + $zones = $this->get_zones( apply_filters( 'zoninator_admin_page_get_zones_args', array() ) ); - $default_active_zone = 0; - if( ! $this->_current_user_can_add_zones() ) { - if( ! empty( $zones ) ) - $default_active_zone = $zones[0]->term_id; - } + $default_active_zone = 0; + if ( ! $this->_current_user_can_add_zones() ) { + if ( ! empty( $zones ) ) { + $default_active_zone = $zones[0]->term_id; + } + } - $active_zone_id = $this->_get_request_var( 'zone_id', $default_active_zone, 'absint' ); - $active_zone = ! empty( $active_zone_id ) ? $this->get_zone( $active_zone_id ) : array(); - if ( ! empty( $active_zone ) ) - $title = __( 'Edit Zone', 'zoninator' ); + $active_zone_id = $this->_get_request_var( 'zone_id', $default_active_zone, 'absint' ); + $active_zone = ! empty( $active_zone_id ) ? $this->get_zone( $active_zone_id ) : array(); + if ( ! empty( $active_zone ) ) { + $title = __( 'Edit Zone', 'zoninator' ); + } - $message = $this->_get_message( $this->_get_get_var( 'message', '', 'urldecode' ) ); - $error = $this->_get_get_var( 'error', '', 'urldecode' ); + $message = $this->_get_message( $this->_get_get_var( 'message', '', 'urldecode' ) ); + $error = $this->_get_get_var( 'error', '', 'urldecode' ); - ?> + ?>

- _current_user_can_add_zones() ) : - $new_link = $this->_get_zone_page_url( array( 'action' => 'new' ) ); ?> - + _current_user_can_add_zones() ) : + $new_link = $this->_get_zone_page_url( array( 'action' => 'new' ) ); + ?> + @@ -308,12 +324,12 @@ function admin_page() {

- +

- +

@@ -321,26 +337,33 @@ function admin_page() {
- admin_page_zone_tabs( $zones, $active_zone_id ); ?> - admin_page_zone_edit( $active_zone ); ?> + admin_page_zone_tabs( $zones, $active_zone_id ); ?> + admin_page_zone_edit( $active_zone ); ?>
- _get_zone_page_url( array( 'action' => 'new' ) ); - ?> + function admin_page_zone_tabs( $zones, $active_zone_id = 0 ) { + $new_link = $this->_get_zone_page_url( array( 'action' => 'new' ) ); + ?> - + Date: Sat, 10 Aug 2024 16:48:09 +0100 Subject: [PATCH 04/56] CS: Rector with PHP 5.5 set https://getrector.com/find-rule?rectorSet=php-php-55 --- lib/zoninator_rest/class-zoninator-rest-bootstrap.php | 2 +- rector.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php index 29feb30..c9f9119 100644 --- a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php +++ b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php @@ -71,7 +71,7 @@ public static function create( $class_loader = null ) { if ( empty( $class_loader ) ) { include_once 'interfaces/class-zoninator-rest-interfaces-classloader.php'; include_once 'class-zoninator-rest-classloader.php'; - $prefix = str_replace( '_Bootstrap', '', __CLASS__ ); + $prefix = str_replace( '_Bootstrap', '', self::class ); $base_dir = self::get_base_dir(); $class_loader = new Zoninator_REST_Classloader( $prefix, $base_dir ); } diff --git a/rector.php b/rector.php index 95d8a5b..f8043c7 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ LongArrayToShortArrayRector::class, ) ) - ->withPhpSets( php53: true ) + ->withPhpSets( php55: true ) ->withTypeCoverageLevel( 0 ); From 3cee9b96778bd9111da5dd1ce2eaaea07a44ccdb Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 16:52:31 +0100 Subject: [PATCH 05/56] CS: Rector with PHP 7.0 set https://getrector.com/find-rule?rectorSet=php-php-70 --- lib/zoninator_rest/class-zoninator-rest-model.php | 5 +---- .../class-zoninator-rest-data-store-customposttype.php | 2 +- .../field/class-zoninator-rest-field-declaration.php | 4 ++-- .../model/class-zoninator-rest-model-settings.php | 8 ++++---- .../class-zoninator-rest-model-declaration-settings.php | 8 ++++---- rector.php | 2 +- tests/unit/class-zoninator-api-controller-test.php | 2 +- zoninator.php | 4 ++-- 8 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/zoninator_rest/class-zoninator-rest-model.php b/lib/zoninator_rest/class-zoninator-rest-model.php index b6998cf..e05eb63 100644 --- a/lib/zoninator_rest/class-zoninator-rest-model.php +++ b/lib/zoninator_rest/class-zoninator-rest-model.php @@ -358,10 +358,7 @@ public function with_data_store( $data_store ) { */ public function get_environment() { $class_name = get_class( $this ); - if ( isset( self::$environments_by_class_name[ $class_name ] ) ) { - return self::$environments_by_class_name[ $class_name ]; - } - return null; + return self::$environments_by_class_name[ $class_name ] ?? null; } /** diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php index 54ff78c..f6ed19d 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php @@ -27,7 +27,7 @@ class Zoninator_REST_Data_Store_CustomPostType extends Zoninator_REST_Data_Store * @param array $args Args. */ public function __construct( $model_prototype = null, $args = array() ) { - $this->post_type = isset( $args['post_type'] ) ? $args['post_type'] : 'post'; + $this->post_type = $args['post_type'] ?? 'post'; parent::__construct( $model_prototype, $args ); } diff --git a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php index 0fd121a..ea23ba0 100644 --- a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php +++ b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php @@ -224,7 +224,7 @@ public function get_sanitizer() { * @return null */ private function value_or_default( $args, $name, $default = null ) { - return isset( $args[ $name ] ) ? $args[ $name ] : $default; + return $args[ $name ] ?? $default; } /** @@ -357,7 +357,7 @@ public function get_description() { * @return string */ public function get_data_transfer_name() { - return isset( $this->data_transfer_name ) ? $this->data_transfer_name : $this->get_name(); + return $this->data_transfer_name ?? $this->get_name(); } /** diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php index 4d727f4..0609613 100644 --- a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php +++ b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php @@ -119,10 +119,10 @@ public function set_id( $new_id ) { private function field_declaration_builder_from_data( $env, $field_data ) { $field_name = $field_data['name']; $field_builder = $env->field( $field_name ); - $default_value = isset( $field_data['std'] ) ? $field_data['std'] : $this->default_for_attribute( $field_data, 'std' ); - $label = isset( $field_data['label'] ) ? $field_data['label'] : $field_name; - $description = isset( $field_data['desc'] ) ? $field_data['desc'] : $label; - $setting_type = isset( $field_data['type'] ) ? $field_data['type'] : null; + $default_value = $field_data['std'] ?? $this->default_for_attribute( $field_data, 'std' ); + $label = $field_data['label'] ?? $field_name; + $description = $field_data['desc'] ?? $label; + $setting_type = $field_data['type'] ?? null; $choices = isset( $field_data['options'] ) ? array_keys( $field_data['options'] ) : null; $field_type = 'string'; diff --git a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php index 7e197d9..b134ad9 100644 --- a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php +++ b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php @@ -119,10 +119,10 @@ function set_id( $model, $new_id ) { private function field_declaration_builder_from_data( $env, $field_data ) { $field_name = $field_data['name']; $field_builder = $env->field( $field_name ); - $default_value = isset( $field_data['std'] ) ? $field_data['std'] : $this->default_for_attribute( $field_data, 'std' ); - $label = isset( $field_data['label'] ) ? $field_data['label'] : $field_name; - $description = isset( $field_data['desc'] ) ? $field_data['desc'] : $label; - $setting_type = isset( $field_data['type'] ) ? $field_data['type'] : null; + $default_value = $field_data['std'] ?? $this->default_for_attribute( $field_data, 'std' ); + $label = $field_data['label'] ?? $field_name; + $description = $field_data['desc'] ?? $label; + $setting_type = $field_data['type'] ?? null; $choices = isset( $field_data['options'] ) ? array_keys( $field_data['options'] ) : null; $field_type = 'string'; diff --git a/rector.php b/rector.php index f8043c7..18eb7b1 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ LongArrayToShortArrayRector::class, ) ) - ->withPhpSets( php55: true ) + ->withPhpSets( php70: true ) ->withTypeCoverageLevel( 0 ); diff --git a/tests/unit/class-zoninator-api-controller-test.php b/tests/unit/class-zoninator-api-controller-test.php index 357915e..b2bfa39 100644 --- a/tests/unit/class-zoninator-api-controller-test.php +++ b/tests/unit/class-zoninator-api-controller-test.php @@ -413,7 +413,7 @@ private function create_a_zone( $slug, $title ) { if ( is_wp_error( $result ) ) { return $result; } - return isset( $result['term_id'] ) ? $result['term_id'] : 0; + return $result['term_id'] ?? 0; } /** diff --git a/zoninator.php b/zoninator.php index e661992..d228de8 100644 --- a/zoninator.php +++ b/zoninator.php @@ -1516,7 +1516,7 @@ function do_zoninator_feeds() { $zone_slug = get_query_var( $this->zone_taxonomy ); $results = $this->get_zone_feed( $zone_slug ); if ( is_wp_error( $results ) ) { - $this->send_user_error( $results->get_error_message() ); + self::send_user_error($results->get_error_message()); } $this->json_return( $results, false ); } @@ -1581,7 +1581,7 @@ private static function status_header_with_message( $status, $message ) { global $wp_header_to_desc; $status = absint( $status ); - $official_message = isset( $wp_header_to_desc[ $status ] ) ? $wp_header_to_desc[ $status ] : ''; + $official_message = $wp_header_to_desc[ $status ] ?? ''; $wp_header_to_desc[ $status ] = $message; status_header( $status ); From 4b4c2a92ece71cec1baf5f4208a41dd982d5a743 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 16:55:38 +0100 Subject: [PATCH 06/56] CS: Rector with PHP 7.1 set https://getrector.com/find-rule?rectorSet=php-php-71 --- includes/class-zoninator-api-controller.php | 30 +++++++++---------- .../class-zoninator-rest-bootstrap.php | 2 +- .../class-zoninator-rest-controller.php | 8 ++--- .../class-zoninator-rest-environment.php | 6 ++-- ...class-zoninator-rest-field-declaration.php | 6 ++-- rector.php | 2 +- zoninator.php | 4 +-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/includes/class-zoninator-api-controller.php b/includes/class-zoninator-api-controller.php index 208c7ca..ed7c2b2 100644 --- a/includes/class-zoninator-api-controller.php +++ b/includes/class-zoninator-api-controller.php @@ -7,21 +7,21 @@ * Class Zoninator_Api_Controller */ class Zoninator_Api_Controller extends Zoninator_REST_Controller { - const ZONE_ITEM_URL_REGEX = '/zones/(?P[\d]+)'; - const ZONE_ITEM_POSTS_URL_REGEX = '/zones/(?P[\d]+)/posts'; - const ZONE_ITEM_POSTS_POST_REGEX = '/zones/(?P[\d]+)/posts/(?P\d+)'; - - const INVALID_ZONE_ID = 'invalid-zone-id'; - const INVALID_POST_ID = 'invalid-post-id'; - const ZONE_ID_POST_ID_REQUIRED = 'zone-id-post-id-required'; - const ZONE_ID_POST_IDS_REQUIRED = 'zone-id-post-ids-required'; - const ZONE_ID_REQUIRED = 'zone-id-required'; - const ZONE_FEED_ERROR = 'zone-feed-error'; - const TERM_REQUIRED = 'term-required'; - const PERMISSION_DENIED = 'permission-denied'; - const ZONE_NOT_FOUND = 'zone-not-found'; - const POST_NOT_FOUND = 'post-not-found'; - const INVALID_ZONE_SETTINGS = 'invalid-zone-settings'; + public const ZONE_ITEM_URL_REGEX = '/zones/(?P[\d]+)'; + public const ZONE_ITEM_POSTS_URL_REGEX = '/zones/(?P[\d]+)/posts'; + public const ZONE_ITEM_POSTS_POST_REGEX = '/zones/(?P[\d]+)/posts/(?P\d+)'; + + public const INVALID_ZONE_ID = 'invalid-zone-id'; + public const INVALID_POST_ID = 'invalid-post-id'; + public const ZONE_ID_POST_ID_REQUIRED = 'zone-id-post-id-required'; + public const ZONE_ID_POST_IDS_REQUIRED = 'zone-id-post-ids-required'; + public const ZONE_ID_REQUIRED = 'zone-id-required'; + public const ZONE_FEED_ERROR = 'zone-feed-error'; + public const TERM_REQUIRED = 'term-required'; + public const PERMISSION_DENIED = 'permission-denied'; + public const ZONE_NOT_FOUND = 'zone-not-found'; + public const POST_NOT_FOUND = 'post-not-found'; + public const INVALID_ZONE_SETTINGS = 'invalid-zone-settings'; /** * Instance * diff --git a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php index c9f9119..c0f382b 100644 --- a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php +++ b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php @@ -18,7 +18,7 @@ * This is the entry point for. */ class Zoninator_REST_Bootstrap { - const MINIMUM_PHP_VERSION = '5.2.0'; + public const MINIMUM_PHP_VERSION = '5.2.0'; /** * The Environment we will use diff --git a/lib/zoninator_rest/class-zoninator-rest-controller.php b/lib/zoninator_rest/class-zoninator-rest-controller.php index e9f8bd4..24ecdc7 100644 --- a/lib/zoninator_rest/class-zoninator-rest-controller.php +++ b/lib/zoninator_rest/class-zoninator-rest-controller.php @@ -13,10 +13,10 @@ * Class Zoninator_REST_Controller */ class Zoninator_REST_Controller extends WP_REST_Controller implements Zoninator_REST_Interfaces_Controller { - const HTTP_CREATED = 201; - const HTTP_OK = 200; - const HTTP_BAD_REQUEST = 400; - const HTTP_NOT_FOUND = 404; + public const HTTP_CREATED = 201; + public const HTTP_OK = 200; + public const HTTP_BAD_REQUEST = 400; + public const HTTP_NOT_FOUND = 404; /** * The bundle this belongs to. diff --git a/lib/zoninator_rest/class-zoninator-rest-environment.php b/lib/zoninator_rest/class-zoninator-rest-environment.php index 77847a1..6929179 100644 --- a/lib/zoninator_rest/class-zoninator-rest-environment.php +++ b/lib/zoninator_rest/class-zoninator-rest-environment.php @@ -19,9 +19,9 @@ * @package Mixtape */ class Zoninator_REST_Environment { - const REGISTRABLE = 'IRegistrable'; - const BUNDLES = 'Bundles'; - const MODELS = 'Models'; + public const REGISTRABLE = 'IRegistrable'; + public const BUNDLES = 'Bundles'; + public const MODELS = 'Models'; /** * This environment's registered REST bundles diff --git a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php index ea23ba0..41afe99 100644 --- a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php +++ b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php @@ -17,18 +17,18 @@ class Zoninator_REST_Field_Declaration { /** * Field A field */ - const FIELD = 'field'; + public const FIELD = 'field'; /** * Meta a meta field */ - const META = 'meta'; + public const META = 'meta'; /** * Derived field kinds get their values from callables. It is also * possible to update their values from callables */ - const DERIVED = 'derived'; + public const DERIVED = 'derived'; /** * Map From * diff --git a/rector.php b/rector.php index 18eb7b1..fee0110 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ LongArrayToShortArrayRector::class, ) ) - ->withPhpSets( php70: true ) + ->withPhpSets( php71: true ) ->withTypeCoverageLevel( 0 ); diff --git a/zoninator.php b/zoninator.php index d228de8..2e73a86 100644 --- a/zoninator.php +++ b/zoninator.php @@ -485,7 +485,7 @@ function admin_page_zone_edit( $zone = null ) {
-
+

@@ -1518,7 +1518,7 @@ function do_zoninator_feeds() { if ( is_wp_error( $results ) ) { self::send_user_error($results->get_error_message()); } - $this->json_return( $results, false ); + $this->json_return( $results ); } return; From de2852fdc5dee2b2929bd898813e4c55b2eac3d0 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 16:59:22 +0100 Subject: [PATCH 07/56] CS: Rector with PHP 7.3 set https://getrector.com/find-rule?rectorSet=php-php-73 --- rector.php | 2 +- zoninator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rector.php b/rector.php index fee0110..fb16233 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ LongArrayToShortArrayRector::class, ) ) - ->withPhpSets( php71: true ) + ->withPhpSets( php73: true ) ->withTypeCoverageLevel( 0 ); diff --git a/zoninator.php b/zoninator.php index 2e73a86..3c9aefc 100644 --- a/zoninator.php +++ b/zoninator.php @@ -748,7 +748,7 @@ function is_zoninator_page() { if ( empty( $screen ) ) { return ! empty( $_REQUEST['page'] ) && sanitize_key( $_REQUEST['page'] ) == $this->key; } else { - return ! empty( $screen->id ) && strstr( $screen->id, $this->key ); + return ! empty( $screen->id ) && strstr( $screen->id, (string) $this->key ); } } From ec14a43b882b3b3f02a1058481f84924569b577d Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 17:07:08 +0100 Subject: [PATCH 08/56] CS: Rector with PHP 7.4 set https://getrector.com/find-rule?rectorSet=php-php-74 --- rector.php | 3 +-- zoninator.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rector.php b/rector.php index fb16233..53e0b89 100644 --- a/rector.php +++ b/rector.php @@ -4,7 +4,6 @@ use Rector\Config\RectorConfig; use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector; -use Rector\ValueObject\PhpVersion; return RectorConfig::configure() ->withPaths( @@ -22,5 +21,5 @@ LongArrayToShortArrayRector::class, ) ) - ->withPhpSets( php73: true ) + ->withPhpSets( php74: true ) ->withTypeCoverageLevel( 0 ); diff --git a/zoninator.php b/zoninator.php index 3c9aefc..56fd39b 100644 --- a/zoninator.php +++ b/zoninator.php @@ -1516,7 +1516,7 @@ function do_zoninator_feeds() { $zone_slug = get_query_var( $this->zone_taxonomy ); $results = $this->get_zone_feed( $zone_slug ); if ( is_wp_error( $results ) ) { - self::send_user_error($results->get_error_message()); + self::send_user_error( $results->get_error_message() ); } $this->json_return( $results ); } From 4f71221a6893bd883ae934a2d39cb49a497652a1 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 18:02:11 +0100 Subject: [PATCH 09/56] CS: Rector with TypeCoverage level 1 --- rector.php | 2 +- tests/bootstrap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rector.php b/rector.php index 53e0b89..91b7ba6 100644 --- a/rector.php +++ b/rector.php @@ -22,4 +22,4 @@ ) ) ->withPhpSets( php74: true ) - ->withTypeCoverageLevel( 0 ); + ->withTypeCoverageLevel( 1 ); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 819b4b9..774ef5f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,7 +11,7 @@ require_once $_tests_dir . '/includes/functions.php'; -function _manually_load_plugin() { +function _manually_load_plugin(): void { $thispath = __DIR__; $file = $thispath . '/../zoninator.php'; require_once realpath( $file ); From 9aaf2e207edaaee86458bbc7c205fbd43ea99b4c Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 18:15:42 +0100 Subject: [PATCH 10/56] CS: Rector with DeadCode level 1 RemoveUnusedForeachKeyRector --- lib/zoninator_rest/class-zoninator-rest-controller.php | 2 +- lib/zoninator_rest/class-zoninator-rest-environment.php | 2 +- lib/zoninator_rest/class-zoninator-rest-model.php | 4 ++-- .../controller/class-zoninator-rest-controller-route.php | 2 +- .../model/class-zoninator-rest-model-settings.php | 2 +- .../class-zoninator-rest-model-declaration-settings.php | 2 +- rector.php | 1 + 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/zoninator_rest/class-zoninator-rest-controller.php b/lib/zoninator_rest/class-zoninator-rest-controller.php index 24ecdc7..8f8a290 100644 --- a/lib/zoninator_rest/class-zoninator-rest-controller.php +++ b/lib/zoninator_rest/class-zoninator-rest-controller.php @@ -89,7 +89,7 @@ public function register( $bundle, $environment ) { $this->setup(); Zoninator_REST_Expect::that( ! empty( $this->base ), 'Need to put a string with a backslash in $base' ); $prefix = $this->controller_bundle->get_prefix(); - foreach ( $this->routes as $pattern => $route ) { + foreach ( $this->routes as $route ) { /** * The route we want to register. * diff --git a/lib/zoninator_rest/class-zoninator-rest-environment.php b/lib/zoninator_rest/class-zoninator-rest-environment.php index 6929179..320df04 100644 --- a/lib/zoninator_rest/class-zoninator-rest-environment.php +++ b/lib/zoninator_rest/class-zoninator-rest-environment.php @@ -183,7 +183,7 @@ public function start() { */ $rest_apis = (array) apply_filters( 'mt_environment_get_rest_apis', $this->rest_apis, $this ); - foreach ( $rest_apis as $k => $bundle ) { + foreach ( $rest_apis as $bundle ) { /** * Register this bundle * diff --git a/lib/zoninator_rest/class-zoninator-rest-model.php b/lib/zoninator_rest/class-zoninator-rest-model.php index e05eb63..e4a4ca0 100644 --- a/lib/zoninator_rest/class-zoninator-rest-model.php +++ b/lib/zoninator_rest/class-zoninator-rest-model.php @@ -149,7 +149,7 @@ public function has( $field ) { public function validate() { $validation_errors = array(); $fields = self::get_fields(); - foreach ( $fields as $key => $field_declaration ) { + foreach ( $fields as $field_declaration ) { $is_valid = $this->run_field_validations( $field_declaration ); if ( is_wp_error( $is_valid ) ) { $validation_errors[] = $is_valid->get_error_data(); @@ -168,7 +168,7 @@ public function validate() { */ public function sanitize() { $fields = self::get_fields(); - foreach ( $fields as $key => $field_declaration ) { + foreach ( $fields as $field_declaration ) { /** * Field Declaration. * diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php index 2e77fff..54e5b39 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php @@ -77,7 +77,7 @@ public function as_array() { $result = array(); $result['pattern'] = $this->pattern; $result['actions'] = array(); - foreach ( $this->actions as $action => $route_action ) { + foreach ( $this->actions as $route_action ) { /** * The route action. * diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php index 0609613..372c988 100644 --- a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php +++ b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php @@ -59,7 +59,7 @@ public function declare_fields() { $settings_per_group = $this->get_settings(); $fields = array(); - foreach ( $settings_per_group as $group_name => $group_data ) { + foreach ( $settings_per_group as $group_data ) { $group_fields = $group_data[1]; foreach ( $group_fields as $field_data ) { diff --git a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php index b134ad9..f5de2d0 100644 --- a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php +++ b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php @@ -57,7 +57,7 @@ function declare_fields( $env ) { $settings_per_group = $this->get_settings(); $fields = array(); - foreach ( $settings_per_group as $group_name => $group_data ) { + foreach ( $settings_per_group as $group_data ) { $group_fields = $group_data[1]; foreach ( $group_fields as $field_data ) { diff --git a/rector.php b/rector.php index 91b7ba6..ad620ac 100644 --- a/rector.php +++ b/rector.php @@ -22,4 +22,5 @@ ) ) ->withPhpSets( php74: true ) + ->withDeadCodeLevel( 1 ) ->withTypeCoverageLevel( 1 ); From 374da2278f0ba07eeacd4b50f409ceb6f3062091 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 18:16:23 +0100 Subject: [PATCH 11/56] CS: Rector with DeadCode level 2 RecastingRemovalRector --- .../type/class-zoninator-rest-type-typedarray.php | 2 +- rector.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php b/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php index 2c93b04..ced62e2 100644 --- a/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php +++ b/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php @@ -54,7 +54,7 @@ public function cast( $value ) { foreach ( $value as $v ) { $new_value[] = $this->item_type_definition->cast( $v ); } - return (array) $new_value; + return $new_value; } /** diff --git a/rector.php b/rector.php index ad620ac..099da3c 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 1 ) + ->withDeadCodeLevel( 2 ) ->withTypeCoverageLevel( 1 ); From 3f645635493fbd1835a0ba3017f0deca97868a54 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 18:19:51 +0100 Subject: [PATCH 12/56] CS: Rector with DeadCode level 7 RemoveNullPropertyInitializationRector --- lib/zoninator_rest/class-zoninator-rest-bootstrap.php | 4 ++-- lib/zoninator_rest/class-zoninator-rest-controller.php | 4 ++-- .../class-zoninator-rest-controller-bundle-builder.php | 2 +- .../controller/class-zoninator-rest-controller-bundle.php | 2 +- .../type/class-zoninator-rest-type-registry.php | 2 +- rector.php | 2 +- tests/unit/class-zoninator-api-controller-test.php | 2 +- zoninator.php | 8 ++++---- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php index c0f382b..d50991b 100644 --- a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php +++ b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php @@ -25,14 +25,14 @@ class Zoninator_REST_Bootstrap { * * @var null|object the Environment implementation. */ - private $environment = null; + private $environment; /** * The class loader we will use * * @var null|Zoninator_REST_Classloader */ - private $class_loader = null; + private $class_loader; /** * Construct a new Bootstrap diff --git a/lib/zoninator_rest/class-zoninator-rest-controller.php b/lib/zoninator_rest/class-zoninator-rest-controller.php index 8f8a290..efeb8de 100644 --- a/lib/zoninator_rest/class-zoninator-rest-controller.php +++ b/lib/zoninator_rest/class-zoninator-rest-controller.php @@ -30,7 +30,7 @@ class Zoninator_REST_Controller extends WP_REST_Controller implements Zoninator_ * * @var string */ - protected $base = null; + protected $base; /** * Our Handlers * @@ -43,7 +43,7 @@ class Zoninator_REST_Controller extends WP_REST_Controller implements Zoninator_ * * @var null|Zoninator_REST_Environment */ - protected $environment = null; + protected $environment; /** * Zoninator_REST_Rest_Api_Controller constructor. diff --git a/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php b/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php index f940050..421b9b0 100644 --- a/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php +++ b/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php @@ -37,7 +37,7 @@ class Zoninator_REST_Controller_Bundle_Builder implements Zoninator_REST_Interfa * * @var Zoninator_REST_Controller_Bundle|null */ - private $bundle = null; + private $bundle; /** * Zoninator_REST_Controller_Bundle_Builder constructor. diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php index 28a03ec..6bd10c8 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php @@ -19,7 +19,7 @@ class Zoninator_REST_Controller_Bundle implements Zoninator_REST_Interfaces_Cont * * @var string|null */ - protected $prefix = null; + protected $prefix; /** * Collection of Mixtape_Rest_Api_Controller subclasses diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php b/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php index f081045..42d0cf9 100644 --- a/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php +++ b/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php @@ -28,7 +28,7 @@ class Zoninator_REST_Type_Registry { * * @var null|array */ - private $types = null; + private $types; /** * Define a new type diff --git a/rector.php b/rector.php index 099da3c..aca1e12 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 2 ) + ->withDeadCodeLevel( 7 ) ->withTypeCoverageLevel( 1 ); diff --git a/tests/unit/class-zoninator-api-controller-test.php b/tests/unit/class-zoninator-api-controller-test.php index b2bfa39..e941378 100644 --- a/tests/unit/class-zoninator-api-controller-test.php +++ b/tests/unit/class-zoninator-api-controller-test.php @@ -7,7 +7,7 @@ class Zoninator_Api_Controller_Test extends WP_UnitTestCase { * * @var Zoninator */ - private $_zoninator = null; + private $_zoninator; /** * REST Server diff --git a/zoninator.php b/zoninator.php index 56fd39b..46dfd4d 100644 --- a/zoninator.php +++ b/zoninator.php @@ -48,17 +48,17 @@ class Zoninator { public $zone_ajax_nonce_action = 'ajax-action'; public $zone_lock_period = 30; // number of seconds a lock is valid for public $zone_max_lock_period = 600; // max number of seconds for all locks in a session - public $post_types = null; - public $zone_detail_defaults = array( + public $post_types; + public $zone_detail_defaults = array( 'description' => '', // Add additional properties here! ); - public $zone_messages = null; + public $zone_messages; public $posts_per_page = 10; /** * @var Zoninator_Api */ - public $rest_api = null; + public $rest_api; /** * @var array|string[] Default post types that support zones. */ From d21774ebc7b053dc7ace066d74ab6064fec56044 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 18:22:38 +0100 Subject: [PATCH 13/56] CS: Rector with DeadCode level 14 SimplifyUselessVariableRector --- .../controller/class-zoninator-rest-controller-action.php | 4 +--- .../field/class-zoninator-rest-field-declaration.php | 3 +-- rector.php | 2 +- tests/unit/class-zoninator-api-controller-test.php | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php index 948a5aa..ce1758c 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php @@ -136,14 +136,12 @@ public function as_array() { $args = $this->controller->get_endpoint_args_for_item_schema( $this->actions_to_http_methods[ $this->action_name ] ); } - $result = array( + return array( 'methods' => $this->actions_to_http_methods[ $this->action_name ], 'callback' => $callable_func, 'permission_callback' => $permission_callback, 'args' => $args, ); - - return $result; } /** diff --git a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php index 41afe99..17f7e1d 100644 --- a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php +++ b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php @@ -347,8 +347,7 @@ public function get_description() { if ( isset( $this->description ) && ! empty( $this->description ) ) { return $this->description; } - $name = ucfirst( str_replace( '_', ' ', $this->get_name() ) ); - return $name; + return ucfirst( str_replace( '_', ' ', $this->get_name() ) ); } /** diff --git a/rector.php b/rector.php index aca1e12..23c3fcb 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 7 ) + ->withDeadCodeLevel( 14 ) ->withTypeCoverageLevel( 1 ); diff --git a/tests/unit/class-zoninator-api-controller-test.php b/tests/unit/class-zoninator-api-controller-test.php index e941378..60771a7 100644 --- a/tests/unit/class-zoninator-api-controller-test.php +++ b/tests/unit/class-zoninator-api-controller-test.php @@ -425,11 +425,10 @@ private function create_a_zone( $slug, $title ) { */ private function add_a_zone( $slug = 'zone-1' ) { $term_factory = new WP_UnitTest_Factory_For_Term(null, Zoninator()->zone_taxonomy); - $zone_id = $term_factory->create_object(array( + return $term_factory->create_object(array( 'name' => 'The Zone Add Post one ' . rand_str(), 'description' => 'Zone ' . rand_str(), 'slug' => $slug, )); - return $zone_id; } } From fee13099ee21bcfe617eb0d6ffb2adc4f8b1ad6d Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 18:27:53 +0100 Subject: [PATCH 14/56] CS: Rector with DeadCode level 19 RemoveNonExistingVarAnnotationRector --- lib/zoninator_rest/class-zoninator-rest-environment.php | 2 -- .../controller/class-zoninator-rest-controller-bundle.php | 2 -- rector.php | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/zoninator_rest/class-zoninator-rest-environment.php b/lib/zoninator_rest/class-zoninator-rest-environment.php index 320df04..4305f0c 100644 --- a/lib/zoninator_rest/class-zoninator-rest-environment.php +++ b/lib/zoninator_rest/class-zoninator-rest-environment.php @@ -186,8 +186,6 @@ public function start() { foreach ( $rest_apis as $bundle ) { /** * Register this bundle - * - * @var Zoninator_REST_Interfaces_Controller_Bundle */ $bundle->register( $this ); } diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php index 6bd10c8..f9ecbf3 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php @@ -78,8 +78,6 @@ function register( $environment ) { foreach ( $endpoints as $endpoint ) { /** * Controller - * - * @var Zoninator_REST_Interfaces_Controller */ $endpoint->register( $this, $this->environment ); } diff --git a/rector.php b/rector.php index 23c3fcb..ed43bad 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 14 ) + ->withDeadCodeLevel( 19 ) ->withTypeCoverageLevel( 1 ); From 04fccfd3102357c2afdbd1eec30647e3f06510e7 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 18:48:48 +0100 Subject: [PATCH 15/56] CS: Rector with DeadCode level 21 RemoveNullTagValueNodeRector --- lib/zoninator_rest/class-zoninator-rest-type.php | 2 -- .../data/store/class-zoninator-rest-data-store-nil.php | 1 - .../field/class-zoninator-rest-field-declaration.php | 3 --- .../interfaces/class-zoninator-rest-interfaces-type.php | 2 -- .../type/class-zoninator-rest-type-nullable.php | 2 -- rector.php | 2 +- zoninator.php | 5 +++-- 7 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/zoninator_rest/class-zoninator-rest-type.php b/lib/zoninator_rest/class-zoninator-rest-type.php index afe0b38..309363a 100644 --- a/lib/zoninator_rest/class-zoninator-rest-type.php +++ b/lib/zoninator_rest/class-zoninator-rest-type.php @@ -39,8 +39,6 @@ function name() { /** * The default value - * - * @return null */ function default_value() { return null; diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php index d6fef95..2125fac 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-nil.php @@ -29,7 +29,6 @@ public function get_entities( $filter = null ) { * Get Entity * * @param int $id Id. - * @return null */ public function get_entity( $id ) { return null; diff --git a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php index 17f7e1d..df5ad47 100644 --- a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php +++ b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php @@ -221,7 +221,6 @@ public function get_sanitizer() { * @param array $args Args. * @param string $name Name. * @param mixed $default Default. - * @return null */ private function value_or_default( $args, $name, $default = null ) { return $args[ $name ] ?? $default; @@ -291,8 +290,6 @@ public function as_item_schema_property() { /** * Get Map From - * - * @return null */ public function get_map_from() { if ( isset( $this->map_from ) && ! empty( $this->map_from ) ) { diff --git a/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php b/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php index 19512ef..1ba208c 100644 --- a/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php +++ b/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php @@ -23,8 +23,6 @@ interface Zoninator_REST_Interfaces_Type { public function cast( $value ); /** * The default value - * - * @return null */ public function default_value(); /** diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php b/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php index 5dde989..1841719 100644 --- a/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php +++ b/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php @@ -32,8 +32,6 @@ function __construct( $item_type_definition ) { /** * Default value as always null. - * - * @return null */ public function default_value() { return null; diff --git a/rector.php b/rector.php index ed43bad..7297cf4 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 19 ) + ->withDeadCodeLevel( 21 ) ->withTypeCoverageLevel( 1 ); diff --git a/zoninator.php b/zoninator.php index 46dfd4d..7452393 100644 --- a/zoninator.php +++ b/zoninator.php @@ -1116,8 +1116,9 @@ function add_zone_posts( $zone, $posts, $append = false ) { } /** - * @param $zone - * @param null $posts + * @param mixed $zone + * @param mixed $posts + * * @return bool|WP_Error */ function remove_zone_posts( $zone, $posts = null ) { From 73a85b9fa1c6c5e8a818219d24a0433e18fa2b48 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 19:51:57 +0100 Subject: [PATCH 16/56] CS: Rector with DeadCode level 26 RemoveUnusedPrivatePropertyRector --- ...ninator-rest-controller-bundle-builder.php | 7 ------- ...class-zoninator-rest-controller-bundle.php | 6 ------ .../class-zoninator-rest-controller-route.php | 20 ++----------------- ...ass-zoninator-rest-data-store-abstract.php | 10 +--------- rector.php | 2 +- .../class-zoninator-api-controller-test.php | 15 -------------- 6 files changed, 4 insertions(+), 56 deletions(-) diff --git a/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php b/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php index 421b9b0..b584046 100644 --- a/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php +++ b/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php @@ -20,12 +20,6 @@ class Zoninator_REST_Controller_Bundle_Builder implements Zoninator_REST_Interfa * @var string */ private $bundle_prefix; - /** - * Env. - * - * @var Zoninator_REST_Environment - */ - private $environment; /** * Endpoint Builders. * @@ -78,7 +72,6 @@ public function with_prefix( $bundle_prefix ) { * @return Zoninator_REST_Controller_Bundle_Builder $this */ public function with_environment( $env ) { - $this->environment = $env; return $this; } diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php index f9ecbf3..0a18be6 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php @@ -27,12 +27,6 @@ class Zoninator_REST_Controller_Bundle implements Zoninator_REST_Interfaces_Cont * @var array */ protected $endpoints = array(); - /** - * Our Endpoint Builders - * - * @var array - */ - private $endpoint_builders; /** * Environment. * diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php index 54e5b39..43491c4 100644 --- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php +++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php @@ -28,20 +28,6 @@ class Zoninator_REST_Controller_Route { */ private $actions; - /** - * Our Controller - * - * @var Zoninator_REST_Controller - */ - private $controller; - - /** - * HTTP Methods - * - * @var array - */ - private $http_methods; - /** * Zoninator_REST_Controller_Route constructor. * @@ -49,10 +35,8 @@ class Zoninator_REST_Controller_Route { * @param string $pattern Pattern. */ public function __construct( $controller, $pattern ) { - $this->controller = $controller; - $this->pattern = $pattern; - $this->actions = array(); - $this->http_methods = explode( ', ', WP_REST_Server::ALLMETHODS ); + $this->pattern = $pattern; + $this->actions = array(); } /** diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php index bf84d9d..6d14df5 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-abstract.php @@ -22,13 +22,6 @@ abstract class Zoninator_REST_Data_Store_Abstract implements Zoninator_REST_Inte */ protected $model_prototype; - /** - * Type Serializers - * - * @var array - */ - private $type_serializers; - /** * Zoninator_REST_Data_Store_Abstract constructor. * @@ -36,8 +29,7 @@ abstract class Zoninator_REST_Data_Store_Abstract implements Zoninator_REST_Inte * @param array $args Args. */ public function __construct( $model_prototype = null, $args = array() ) { - $this->type_serializers = array(); - $this->args = $args; + $this->args = $args; Zoninator_REST_Expect::is_a( $model_prototype, 'Zoninator_REST_Interfaces_Model' ); $this->set_model_factory( $model_prototype ); } diff --git a/rector.php b/rector.php index 7297cf4..75db8f3 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 21 ) + ->withDeadCodeLevel( 26 ) ->withTypeCoverageLevel( 1 ); diff --git a/tests/unit/class-zoninator-api-controller-test.php b/tests/unit/class-zoninator-api-controller-test.php index 60771a7..798cc04 100644 --- a/tests/unit/class-zoninator-api-controller-test.php +++ b/tests/unit/class-zoninator-api-controller-test.php @@ -2,13 +2,6 @@ class Zoninator_Api_Controller_Test extends WP_UnitTestCase { - /** - * The Mighty Zoninator! - * - * @var Zoninator - */ - private $_zoninator; - /** * REST Server * @@ -16,13 +9,6 @@ class Zoninator_Api_Controller_Test extends WP_UnitTestCase { */ protected $rest_server; - /** - * Post ID - * - * @var int - */ - private $_post_id = 0; - /** * Admin ID * @@ -171,7 +157,6 @@ function setUp(): void { global $wp_rest_server; $this->rest_server = new Spy_REST_Server; $wp_rest_server = $this->rest_server; - $this->_zoninator = Zoninator(); $admin = get_user_by( 'email', 'rest_api_admin_user@test.com' ); if ( false === $admin ) { $this->admin_id = wp_create_user( From b51a88e3114871b524547fdf2d07b4622e4cf7a6 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 20:30:13 +0100 Subject: [PATCH 17/56] CS: Rector with DeadCode level 40 RemoveUnreachableStatementRector --- rector.php | 2 +- zoninator.php | 18 +----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/rector.php b/rector.php index 75db8f3..9e4ba78 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 26 ) + ->withDeadCodeLevel( 40 ) ->withTypeCoverageLevel( 1 ); diff --git a/zoninator.php b/zoninator.php index 7452393..3b80c25 100644 --- a/zoninator.php +++ b/zoninator.php @@ -258,7 +258,6 @@ function admin_controller() { ); exit; } - break; case 'delete': $zone_id = $this->_get_request_var( 'zone_id', 0, 'absint' ); @@ -1593,29 +1592,14 @@ private static function status_header_with_message( $status, $message ) { // TODO: Caching needs to be testing properly before being implemented! function get_zone_cache_key( $zone, $args = array() ) { return ''; - - $meta_key = $this->get_zone_meta_key( $zone ); - $hash = md5( serialize( $args ) ); - return $meta_key . $hash; } function get_zone_posts_from_cache( $zone, $args = array() ) { - return false; // TODO: implement - - $meta_key = $this->get_zone_meta_key( $zone ); - $cache_key = $this->get_zone_cache_key( $zone, $args ); - if ( $posts = wp_cache_get( $cache_key, $meta_key ) ) { - return $posts; - } return false; } function add_zone_posts_to_cache( $posts, $zone, $args = array() ) { - return; // TODO: implement - - $meta_key = $this->get_zone_meta_key( $zone ); - $cache_key = $this->get_zone_cache_key( $zone, $args ); - wp_cache_set( $cache_key, $posts, $meta_key ); + return; } // Handle 4.2 term-splitting From adbc67b195103ff394da9fea51f87ca5abc8c97c Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 10 Aug 2024 21:22:32 +0100 Subject: [PATCH 18/56] CS: Rector with DeadCode level 41 RemoveUnusedVariableAssignRector --- ...class-zoninator-rest-data-store-customposttype.php | 11 +++++------ rector.php | 2 +- tests/unit/class-zoninator-api-controller-test.php | 4 ++-- zoninator.php | 3 --- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php index f6ed19d..e5b36ac 100644 --- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php +++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php @@ -43,7 +43,7 @@ public function get_entities( $filter = null ) { array( 'post_type' => $this->post_type, 'post_status' => 'any', - ) + ) ); $posts = $query->get_posts(); $collection = array(); @@ -76,9 +76,8 @@ public function get_entity( $id ) { * @throws Zoninator_REST_Exception If something goes wrong. */ private function create_from_post( $post ) { - $field_declarations = $this->get_model_prototype()->get_fields(); - $raw_post_data = $post->to_array(); - $raw_meta_data = get_post_meta( $post->ID ); // assumes we are only ever adding one postmeta per key. + $raw_post_data = $post->to_array(); + $raw_meta_data = get_post_meta( $post->ID ); // assumes we are only ever adding one postmeta per key. $flattened_meta = array(); foreach ( $raw_meta_data as $key => $value_arr ) { @@ -90,7 +89,7 @@ private function create_from_post( $post ) { $merged_data, array( 'deserialize' => true, - ) + ) ); } @@ -108,7 +107,7 @@ public function delete( $model, $args = array() ) { $args, array( 'force_delete' => false, - ) + ) ); do_action( 'mixtape_data_store_delete_model_before', $model, $id ); diff --git a/rector.php b/rector.php index 9e4ba78..2a4e9f1 100644 --- a/rector.php +++ b/rector.php @@ -22,5 +22,5 @@ ) ) ->withPhpSets( php74: true ) - ->withDeadCodeLevel( 40 ) + ->withDeadCodeLevel( 41 ) ->withTypeCoverageLevel( 1 ); diff --git a/tests/unit/class-zoninator-api-controller-test.php b/tests/unit/class-zoninator-api-controller-test.php index 798cc04..2f42a5d 100644 --- a/tests/unit/class-zoninator-api-controller-test.php +++ b/tests/unit/class-zoninator-api-controller-test.php @@ -305,7 +305,7 @@ function test_update_zone_posts_responds_with_not_found_if_zone_not_exist() { */ function test_update_zone_posts_fails_if_invalid_data() { $this->login_as_admin(); - $post_id = $this->_insert_a_post(); + $this->_insert_a_post(); $zone_id = $this->create_a_zone( 'test-zone', 'Test Zone' ); $response = $this->put( '/zoninator/v1/zones/' . $zone_id . '/posts', array() ); $this->assertResponseStatus( $response, 400 ); @@ -318,7 +318,7 @@ function test_update_zone_posts_fails_if_invalid_data() { */ function test_update_zone_posts_fails_if_invalid_post_id() { $this->login_as_admin(); - $post_id = $this->_insert_a_post(); + $this->_insert_a_post(); $zone_id = $this->create_a_zone( 'test-zone', 'Test Zone' ); $response = $this->put( '/zoninator/v1/zones/' . $zone_id . '/posts', array( 'post_ids' => array( 123456789 ), diff --git a/zoninator.php b/zoninator.php index 3b80c25..356103e 100644 --- a/zoninator.php +++ b/zoninator.php @@ -284,8 +284,6 @@ function admin_controller() { function admin_page() { global $zoninator_admin_page; - $view = $this->_get_value_or_default( 'view', $zoninator_admin_page, 'edit.php' ); - $view = sprintf( '%s/views/%s', ZONINATOR_PATH, $view ); $title = __( 'Zones', 'zoninator' ); $zones = $this->get_zones( apply_filters( 'zoninator_admin_page_get_zones_args', array() ) ); @@ -345,7 +343,6 @@ function admin_page() { } function admin_page_zone_tabs( $zones, $active_zone_id = 0 ) { - $new_link = $this->_get_zone_page_url( array( 'action' => 'new' ) ); ?>