From 582f62806ff0cc80b68e32a5a53dbbc15697292e Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Fri, 21 Oct 2016 19:09:16 -0200 Subject: [PATCH 01/15] Fix PSR-2 issues --- src/Field/Repeater.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Field/Repeater.php b/src/Field/Repeater.php index 98f3f53..b87ab5f 100644 --- a/src/Field/Repeater.php +++ b/src/Field/Repeater.php @@ -51,7 +51,7 @@ public function get() */ protected function retrieveIdFromFieldName($metaKey, $fieldName) { - return (int) str_replace("{$fieldName}_", '', $metaKey); + return (int)str_replace("{$fieldName}_", '', $metaKey); } /** @@ -76,7 +76,7 @@ protected function fetchPostsMeta($fieldName, Post $post) { $count = $this->fetchValue($fieldName, $post); $builder = $this->postMeta->where('post_id', $post->ID); - $builder->where(function($query) use ($count, $fieldName) { + $builder->where(function ($query) use ($count, $fieldName) { foreach (range(0, $count - 1) as $i) { $query->orWhere('meta_key', 'like', "{$fieldName}_{$i}_%"); } From e1033bfd3cdb664d8feaada3d2b59a91c5524ee1 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Sat, 22 Oct 2016 23:14:57 -0200 Subject: [PATCH 02/15] Add "what is missing" section on readme file --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index be7da0f..40902a0 100644 --- a/readme.md +++ b/readme.md @@ -69,6 +69,12 @@ First we should create the fields classes and the test cases. After we have to s | Repeater | partially | [@jgrossi](http://github.com/jgrossi) | `Collection` of fields | | Flexible Content | missing | | | +## What is missing + +- Create more unit tests for `Repeater` field; +- Implement the `Flexible Content` field with unit tests; +- Improve performance. Currently the plugin makes one SQL query for each field. This goal is to improve that using `whereIn()` clauses. + # Contributing All contributions are welcome. Before submitting your Pull Request take a look on the following guidelines: From d4b0c97670155196c542b1838aa98f4ed1861b45 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Sat, 22 Oct 2016 23:19:02 -0200 Subject: [PATCH 03/15] Merge "what is missing" section info in readme --- readme.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index 40902a0..57f7320 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,10 @@ > Fetch all Advanced Custom Fields (ACF) fields inside Corcel easily. +* [Installation](#instalation) +* [Usage](#usage) + + # Installation To install the ACF plugin for Corcel is easy: @@ -31,9 +35,13 @@ First ACF fetches the `meta_value` in `wp_postmeta` table, where the `meta_key` This plugin works with a basic logic inside `Corcel\Acf\Field\BasicField` abstract class, that has a lot of useful functions to return the `field key`, the `value`, etc. The `Corcel\Acf\FieldFactory` is responsible to return the correct field instance according the field type, so, if the field type is `post_object` it return an instance of `Corcel\Acf\Field\PostObject`, and it will returns in the `get()` method an instance of `Corcel\Post`. -## What's Missing +## What is Missing -First we should create the fields classes and the test cases. After we have to setup how Corcel is going to work with the `corcel/acf` plugin, returning the custom field value in the format `$post->meta->field` or maybe `$post->acf->field` having different behavior. This should be done yet! +First we should create the fields classes and the test cases. After we have to setup how Corcel is going to work with the `corcel/acf` plugin, returning the custom field value in the format `$post->meta->field` or maybe `$post->acf->field` having different behavior (done!). + + - Create more unit tests for `Repeater` field; + - Implement the `Flexible Content` field with unit tests; + - Improve performance. Currently the plugin makes one SQL query for each field. This goal is to improve that using `whereIn()` clauses. Some fields are still missing (check table below and contribute). @@ -69,12 +77,6 @@ First we should create the fields classes and the test cases. After we have to s | Repeater | partially | [@jgrossi](http://github.com/jgrossi) | `Collection` of fields | | Flexible Content | missing | | | -## What is missing - -- Create more unit tests for `Repeater` field; -- Implement the `Flexible Content` field with unit tests; -- Improve performance. Currently the plugin makes one SQL query for each field. This goal is to improve that using `whereIn()` clauses. - # Contributing All contributions are welcome. Before submitting your Pull Request take a look on the following guidelines: From 0d14d63bba4672735e1ce0cfd38810f40cc0d108 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Sat, 22 Oct 2016 23:21:16 -0200 Subject: [PATCH 04/15] Add table of contents in readme file --- readme.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 57f7320..995d440 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,12 @@ * [Installation](#instalation) * [Usage](#usage) - + - [The Idea](#the-idea) + - [What is Missing](#what-is-missing) + - [Fields](#fields) +* [Contributing](#contributing) + - [Running Tests](#running-tests) +* [Licence](#licence) # Installation @@ -99,6 +104,6 @@ You should import the `database.sql` file to a database inside your local enviro > If you want to access the WordPress Admin Panel just use username as `admin` and password `123456`. -## Licence +# Licence [MIT License](http://jgrossi.mit-license.org/) © Junior Grossi \ No newline at end of file From 5dd5898094e59839f3110fa167ba6d08d76b3673 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Sat, 22 Oct 2016 23:22:51 -0200 Subject: [PATCH 05/15] Fix typo in table of contents in readme file --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 995d440..67dc8af 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ > Fetch all Advanced Custom Fields (ACF) fields inside Corcel easily. -* [Installation](#instalation) +* [Installation](#installation) * [Usage](#usage) - [The Idea](#the-idea) - [What is Missing](#what-is-missing) From ddd3a7d213210db48ef2deda609029e0405c7e22 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Sat, 22 Oct 2016 23:27:00 -0200 Subject: [PATCH 06/15] Add short description about the plugin in readme --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index 67dc8af..a3d3804 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,10 @@ > Fetch all Advanced Custom Fields (ACF) fields inside Corcel easily. +This Corcel plugin allows you to fetch WordPress custom fields created by the [ACF](http://advancedcustomfields.com) plugin using the same syntax of Eloquent, from the [Laravel Framework](http://laravel.com). You can use Eloquent models and Collections to improve your development, using the WordPress backend with any PHP application. + +For more information about how Corcel works please visit [the repository](http://github.com/jgrossi/corcel). + * [Installation](#installation) * [Usage](#usage) - [The Idea](#the-idea) From b64fa1c2ef18653502ea8355ae4b73d9b2164109 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Sun, 23 Oct 2016 23:29:24 -0200 Subject: [PATCH 07/15] Add badges information in readme file --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index a3d3804..9d4f62d 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,10 @@ > Fetch all Advanced Custom Fields (ACF) fields inside Corcel easily. +[![Travis](https://travis-ci.org/jgrossi/corcel.svg?branch=master)](https://travis-ci.org/corcel/acf?branch=master) +[![Packagist](https://img.shields.io/packagist/v/corcel/acf.svg)](https://github.com/corcel/acf/releases) +[![Packagist](https://img.shields.io/packagist/dt/corcel/acf.svg)](https://packagist.org/packages/corcel/acf) + This Corcel plugin allows you to fetch WordPress custom fields created by the [ACF](http://advancedcustomfields.com) plugin using the same syntax of Eloquent, from the [Laravel Framework](http://laravel.com). You can use Eloquent models and Collections to improve your development, using the WordPress backend with any PHP application. For more information about how Corcel works please visit [the repository](http://github.com/jgrossi/corcel). From bc460a499d881b42e8164e160aef36cd4f846ae8 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Mon, 24 Oct 2016 10:01:43 -0200 Subject: [PATCH 08/15] Change position of badges on readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 9d4f62d..ba210b4 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,11 @@ # Corcel ACF Plugin -> Fetch all Advanced Custom Fields (ACF) fields inside Corcel easily. - [![Travis](https://travis-ci.org/jgrossi/corcel.svg?branch=master)](https://travis-ci.org/corcel/acf?branch=master) [![Packagist](https://img.shields.io/packagist/v/corcel/acf.svg)](https://github.com/corcel/acf/releases) [![Packagist](https://img.shields.io/packagist/dt/corcel/acf.svg)](https://packagist.org/packages/corcel/acf) +> Fetch all Advanced Custom Fields (ACF) fields inside Corcel easily. + This Corcel plugin allows you to fetch WordPress custom fields created by the [ACF](http://advancedcustomfields.com) plugin using the same syntax of Eloquent, from the [Laravel Framework](http://laravel.com). You can use Eloquent models and Collections to improve your development, using the WordPress backend with any PHP application. For more information about how Corcel works please visit [the repository](http://github.com/jgrossi/corcel). From 34f85af0996b86c9e2ac44bf73b404265b23a0cd Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 2 Nov 2016 18:32:18 -0200 Subject: [PATCH 09/15] Add an option to pass the field type through the field factory make() method --- src/FieldFactory.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/FieldFactory.php b/src/FieldFactory.php index f605d2c..31f50a0 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -32,18 +32,21 @@ private function __construct() /** * @param string $name * @param Post $post + * @param null|string $type * @return FieldInterface|Collection|string */ - public static function make($name, Post $post) + public static function make($name, Post $post, $type = null) { - $fakeText = new Text; - $key = $fakeText->fetchFieldKey($name, $post); + if (null === $type) { + $fakeText = new Text; + $key = $fakeText->fetchFieldKey($name, $post); - if ($key === null) { // Field does not exist - return null; - } + if ($key === null) { // Field does not exist + return null; + } - $type = $fakeText->fetchFieldType($key); + $type = $fakeText->fetchFieldType($key); + } switch ($type) { case 'text': From 8a033b915d5273e670373a393ae1a24d20aaf37c Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 2 Nov 2016 18:37:02 -0200 Subject: [PATCH 10/15] Add MissingFieldNameException class --- src/Exception/MissingFieldNameException.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/Exception/MissingFieldNameException.php diff --git a/src/Exception/MissingFieldNameException.php b/src/Exception/MissingFieldNameException.php new file mode 100644 index 0000000..6173564 --- /dev/null +++ b/src/Exception/MissingFieldNameException.php @@ -0,0 +1,14 @@ + + */ +class MissingFieldNameException extends \Exception +{ + +} \ No newline at end of file From 42191937f176d618cd73ad2a10facbef6ff07674 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 2 Nov 2016 18:39:38 -0200 Subject: [PATCH 11/15] Add function helpers improving performance --- src/AdvancedCustomFields.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/AdvancedCustomFields.php b/src/AdvancedCustomFields.php index b75434a..2406d3d 100644 --- a/src/AdvancedCustomFields.php +++ b/src/AdvancedCustomFields.php @@ -2,6 +2,7 @@ namespace Corcel\Acf; +use Corcel\Acf\Exception\MissingFieldNameException; use Corcel\Post; /** @@ -37,10 +38,31 @@ public function get($fieldName) /** * @param string $name + * * @return mixed */ public function __get($name) { return $this->get($name); } + + /** + * Make possible to call $post->acf->fieldType('fieldName') + * + * @param string$name + * @param array $arguments + * + * @return mixed + * @throws MissingFieldNameException + */ + function __call($name, $arguments) + { + if (! isset($arguments[0])) { + throw new MissingFieldNameException('The field name is missing'); + } + + $field = FieldFactory::make($arguments[0], $this->post, snake_case($name)); + + return $field->get(); + } } From bf14c1724b7384b89ec68a0a1515a542f0a43acf Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 2 Nov 2016 18:40:14 -0200 Subject: [PATCH 12/15] Include test for functions helpers --- tests/CorcelIntegrationTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/CorcelIntegrationTest.php b/tests/CorcelIntegrationTest.php index c6a0fb3..2cc08bd 100644 --- a/tests/CorcelIntegrationTest.php +++ b/tests/CorcelIntegrationTest.php @@ -12,4 +12,10 @@ public function testIfCorcelIntegrationIsWorking() $post = Post::find(56); $this->assertEquals('admin', $post->acf->fake_user->nickname); } + + public function testUsageOfHelperFunctions() + { + $post = Post::find(56); + $this->assertEquals('admin', $post->acf->user('fake_user')->nickname); + } } From a71a266de36b837114014b696982720d8628c1b8 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 2 Nov 2016 18:42:03 -0200 Subject: [PATCH 13/15] Add repeater field to field factory --- src/FieldFactory.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/FieldFactory.php b/src/FieldFactory.php index 31f50a0..acb46a6 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -9,6 +9,7 @@ use Corcel\Acf\Field\Image; use Corcel\Acf\Field\PageLink; use Corcel\Acf\Field\PostObject; +use Corcel\Acf\Field\Repeater; use Corcel\Acf\Field\Select; use Corcel\Acf\Field\Term; use Corcel\Acf\Field\Text; @@ -99,6 +100,9 @@ public static function make($name, Post $post, $type = null) case 'time_picker': $field = new DateTime(); break; + case 'repeater': + $field = new Repeater(); + break; } $field->process($name, $post); From 8eb8f7ed09136f14ffe3711be929377f846df9e4 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 2 Nov 2016 18:47:20 -0200 Subject: [PATCH 14/15] Include function helpers information in readme file --- readme.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/readme.md b/readme.md index ba210b4..60b6a54 100644 --- a/readme.md +++ b/readme.md @@ -38,6 +38,20 @@ $post = Post::find(1); echo $post->acf->url; // returns the url custom field created using ACF ``` +## Performance + +When using something like `$post->acf->url` the plugin has to make some extra SQL queries to get the field type according ACF approach. So we created another way to get that without making those extra queries. You have only the inform the plugin what is the post type, as a function: + + ```php + // Extra queries way + echo $post->acf->author_username; // it's a User field + + // Without extra queries + echo $post->acf->user('author_username'); + ``` + + > PS: The method names should be written in `camelCase()` format. So, for example, for the field type `date_picker` you should write `$post->acf->datePicker('fieldName')`. The plugin does the conversion from `camelCase` to `snake_case` for you. + ## The Idea Using the default `$post->meta->field_name` in Corcel returns the value of the `meta_value` column in the `wp_postmeta` table. It can be a string, an integer or even a serialized array. The problem is, when you're using ACF this value can be more than that. If you have an integer, for example, it can be a `post id`, an `user id` or even an array of `posts ids`. From 273a5c901e20030c838dd232539854083fc90cb5 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 2 Nov 2016 18:52:18 -0200 Subject: [PATCH 15/15] Fix PSR-2 using php-cs-fixer --- src/AdvancedCustomFields.php | 10 +++++----- src/Exception/MissingFieldNameException.php | 6 ++---- src/Field/BasicField.php | 14 ++++++++------ src/Field/Boolean.php | 5 ++--- src/Field/DateTime.php | 6 +++--- src/Field/File.php | 5 ++--- src/Field/Gallery.php | 3 +-- src/Field/Image.php | 9 ++++++--- src/Field/PageLink.php | 3 +-- src/Field/PostObject.php | 5 ++--- src/Field/Repeater.php | 14 +++++++++----- src/Field/Term.php | 7 ++----- src/Field/Text.php | 6 +----- src/Field/User.php | 7 ++----- src/FieldFactory.php | 11 +++++------ src/FieldInterface.php | 5 ++--- tests/BasicFieldsTest.php | 4 ++-- tests/ChoicesFieldsTest.php | 6 +----- tests/ContentFieldsTest.php | 4 ++-- tests/CorcelIntegrationTest.php | 2 +- tests/FieldFactoryTest.php | 3 +-- tests/LayoutFieldsTest.php | 2 +- tests/RelationalFieldsTest.php | 2 +- tests/config/bootstrap.php | 3 +-- 24 files changed, 63 insertions(+), 79 deletions(-) diff --git a/src/AdvancedCustomFields.php b/src/AdvancedCustomFields.php index 2406d3d..08c914b 100644 --- a/src/AdvancedCustomFields.php +++ b/src/AdvancedCustomFields.php @@ -6,9 +6,8 @@ use Corcel\Post; /** - * Class AdvancedCustomFields + * Class AdvancedCustomFields. * - * @package Corcel\Acf * @author Junior Grossi */ class AdvancedCustomFields @@ -47,17 +46,18 @@ public function __get($name) } /** - * Make possible to call $post->acf->fieldType('fieldName') + * Make possible to call $post->acf->fieldType('fieldName'). * * @param string$name * @param array $arguments * * @return mixed + * * @throws MissingFieldNameException */ - function __call($name, $arguments) + public function __call($name, $arguments) { - if (! isset($arguments[0])) { + if (!isset($arguments[0])) { throw new MissingFieldNameException('The field name is missing'); } diff --git a/src/Exception/MissingFieldNameException.php b/src/Exception/MissingFieldNameException.php index 6173564..9c6e855 100644 --- a/src/Exception/MissingFieldNameException.php +++ b/src/Exception/MissingFieldNameException.php @@ -3,12 +3,10 @@ namespace Corcel\Acf\Exception; /** - * Class MissingFieldNameException + * Class MissingFieldNameException. * - * @package Corcel\Acf\Exception * @author Junior Grossi */ class MissingFieldNameException extends \Exception { - -} \ No newline at end of file +} diff --git a/src/Field/BasicField.php b/src/Field/BasicField.php index 5ea33f4..25cca15 100644 --- a/src/Field/BasicField.php +++ b/src/Field/BasicField.php @@ -6,9 +6,8 @@ use Corcel\PostMeta; /** - * Class BasicField + * Class BasicField. * - * @package Corcel\Acf\Field * @author Junior Grossi */ abstract class BasicField @@ -44,7 +43,7 @@ abstract class BasicField protected $value; /** - * Constructor method + * Constructor method. */ public function __construct() { @@ -52,10 +51,11 @@ public function __construct() } /** - * Get the value of a field according it's post ID + * Get the value of a field according it's post ID. * * @param string $field - * @param Post $post + * @param Post $post + * * @return array|string */ public function fetchValue($field, Post $post) @@ -80,7 +80,8 @@ public function fetchValue($field, Post $post) /** * @param string $fieldName - * @param Post $post + * @param Post $post + * * @return string */ public function fetchFieldKey($fieldName, Post $post) @@ -103,6 +104,7 @@ public function fetchFieldKey($fieldName, Post $post) /** * @param string $fieldKey + * * @return string */ public function fetchFieldType($fieldKey) diff --git a/src/Field/Boolean.php b/src/Field/Boolean.php index 3ba4d0a..119fa95 100644 --- a/src/Field/Boolean.php +++ b/src/Field/Boolean.php @@ -5,9 +5,8 @@ use Corcel\Acf\FieldInterface; /** - * Class Boolean + * Class Boolean. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class Boolean extends Text implements FieldInterface @@ -17,6 +16,6 @@ class Boolean extends Text implements FieldInterface */ public function get() { - return (bool)parent::get(); + return (bool) parent::get(); } } diff --git a/src/Field/DateTime.php b/src/Field/DateTime.php index 9920f2e..fc3aba1 100644 --- a/src/Field/DateTime.php +++ b/src/Field/DateTime.php @@ -7,9 +7,8 @@ use Corcel\Post; /** - * Class DateTime + * Class DateTime. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class DateTime extends BasicField implements FieldInterface @@ -21,7 +20,7 @@ class DateTime extends BasicField implements FieldInterface /** * @param string $fieldName - * @param Post $post + * @param Post $post */ public function process($fieldName, Post $post) { @@ -40,6 +39,7 @@ public function get() /** * @param string $dateString + * * @return string */ protected function getDateFormatFromString($dateString) diff --git a/src/Field/File.php b/src/Field/File.php index cc20ad9..c7ab0a9 100644 --- a/src/Field/File.php +++ b/src/Field/File.php @@ -6,9 +6,8 @@ use Corcel\Post; /** - * Class File + * Class File. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class File extends BasicField implements FieldInterface @@ -45,7 +44,7 @@ class File extends BasicField implements FieldInterface /** * @param string $field - * @param Post $post + * @param Post $post */ public function process($field, Post $post) { diff --git a/src/Field/Gallery.php b/src/Field/Gallery.php index 78c2f5e..3ffb9ce 100644 --- a/src/Field/Gallery.php +++ b/src/Field/Gallery.php @@ -7,9 +7,8 @@ use Illuminate\Support\Collection; /** - * Class Gallery + * Class Gallery. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class Gallery extends Image implements FieldInterface diff --git a/src/Field/Image.php b/src/Field/Image.php index 17a839c..be19ae6 100644 --- a/src/Field/Image.php +++ b/src/Field/Image.php @@ -7,9 +7,8 @@ use Illuminate\Database\Eloquent\Collection; /** - * Class Image + * Class Image. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class Image extends BasicField implements FieldInterface @@ -56,7 +55,7 @@ class Image extends BasicField implements FieldInterface /** * @param string $field - * @param Post $post + * @param Post $post */ public function process($field, Post $post) { @@ -89,6 +88,7 @@ protected function fillFields(Post $attachment) /** * @param string $size + * * @return Image */ public function size($size) @@ -102,6 +102,7 @@ public function size($size) /** * @param array $data + * * @return Image */ protected function fillThumbnailFields(array $data) @@ -117,6 +118,7 @@ protected function fillThumbnailFields(array $data) /** * @param Post $attachment + * * @return array */ protected function fetchMetadataValue(Post $attachment) @@ -130,6 +132,7 @@ protected function fetchMetadataValue(Post $attachment) /** * @param Collection $attachments + * * @return Collection */ protected function fetchMultipleMetadataValues(Collection $attachments) diff --git a/src/Field/PageLink.php b/src/Field/PageLink.php index 14987e9..a81dee2 100644 --- a/src/Field/PageLink.php +++ b/src/Field/PageLink.php @@ -5,9 +5,8 @@ use Corcel\Acf\FieldInterface; /** - * Class PageLink + * Class PageLink. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class PageLink extends PostObject implements FieldInterface diff --git a/src/Field/PostObject.php b/src/Field/PostObject.php index 0180c46..523e27f 100644 --- a/src/Field/PostObject.php +++ b/src/Field/PostObject.php @@ -6,9 +6,8 @@ use Corcel\Post; /** - * Class PostObject + * Class PostObject. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class PostObject extends BasicField implements FieldInterface @@ -20,7 +19,7 @@ class PostObject extends BasicField implements FieldInterface /** * @param string $fieldName - * @param Post $post + * @param Post $post */ public function process($fieldName, Post $post) { diff --git a/src/Field/Repeater.php b/src/Field/Repeater.php index b87ab5f..fd1c0ad 100644 --- a/src/Field/Repeater.php +++ b/src/Field/Repeater.php @@ -9,9 +9,8 @@ use Illuminate\Support\Collection; /** - * Class Repeater + * Class Repeater. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class Repeater extends BasicField implements FieldInterface @@ -23,7 +22,7 @@ class Repeater extends BasicField implements FieldInterface /** * @param string $fieldName - * @param Post $post + * @param Post $post */ public function process($fieldName, Post $post) { @@ -47,17 +46,19 @@ public function get() /** * @param string $metaKey * @param string $fieldName + * * @return int */ protected function retrieveIdFromFieldName($metaKey, $fieldName) { - return (int)str_replace("{$fieldName}_", '', $metaKey); + return (int) str_replace("{$fieldName}_", '', $metaKey); } /** * @param string $metaKey * @param string $fieldName - * @param int $id + * @param int $id + * * @return string */ protected function retrieveFieldName($metaKey, $fieldName, $id) @@ -70,6 +71,7 @@ protected function retrieveFieldName($metaKey, $fieldName, $id) /** * @param $fieldName * @param Post $post + * * @return mixed */ protected function fetchPostsMeta($fieldName, Post $post) @@ -88,6 +90,7 @@ protected function fetchPostsMeta($fieldName, Post $post) /** * @param $fieldName * @param $builder + * * @return mixed */ protected function fetchFields($fieldName, Builder $builder) @@ -99,6 +102,7 @@ protected function fetchFields($fieldName, Builder $builder) $field = FieldFactory::make($meta->meta_key, $this->post->find($meta->post_id)); $fields[$id][$name] = $field->get(); } + return $fields; } } diff --git a/src/Field/Term.php b/src/Field/Term.php index 9d5265d..aa40923 100644 --- a/src/Field/Term.php +++ b/src/Field/Term.php @@ -7,9 +7,8 @@ use Illuminate\Support\Collection; /** - * Class Term + * Class Term. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class Term extends BasicField implements FieldInterface @@ -24,8 +23,6 @@ class Term extends BasicField implements FieldInterface */ protected $term; - /** - */ public function __construct() { parent::__construct(); @@ -34,7 +31,7 @@ public function __construct() /** * @param string $fieldName - * @param Post $post + * @param Post $post */ public function process($fieldName, Post $post) { diff --git a/src/Field/Text.php b/src/Field/Text.php index f9c23b1..3c9ce0d 100644 --- a/src/Field/Text.php +++ b/src/Field/Text.php @@ -6,9 +6,8 @@ use Corcel\Post; /** - * Class Text + * Class Text. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class Text extends BasicField implements FieldInterface @@ -18,9 +17,6 @@ class Text extends BasicField implements FieldInterface */ protected $value; - /** - * @return void - */ public function process($field, Post $post) { $this->value = $this->fetchValue($field, $post); diff --git a/src/Field/User.php b/src/Field/User.php index c025160..5d33ee5 100644 --- a/src/Field/User.php +++ b/src/Field/User.php @@ -6,9 +6,8 @@ use Corcel\Post; /** - * Class User + * Class User. * - * @package Corcel\Acf\Field * @author Junior Grossi */ class User extends BasicField implements FieldInterface @@ -23,8 +22,6 @@ class User extends BasicField implements FieldInterface */ protected $value; - /** - */ public function __construct() { parent::__construct(); @@ -33,7 +30,7 @@ public function __construct() /** * @param string $fieldName - * @param Post $post + * @param Post $post */ public function process($fieldName, Post $post) { diff --git a/src/FieldFactory.php b/src/FieldFactory.php index acb46a6..b3081d0 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -18,28 +18,27 @@ use Illuminate\Support\Collection; /** - * Class FieldFactory + * Class FieldFactory. * - * @package Corcel\Acf * @author Junior Grossi */ class FieldFactory { private function __construct() { - // } /** - * @param string $name - * @param Post $post + * @param string $name + * @param Post $post * @param null|string $type + * * @return FieldInterface|Collection|string */ public static function make($name, Post $post, $type = null) { if (null === $type) { - $fakeText = new Text; + $fakeText = new Text(); $key = $fakeText->fetchFieldKey($name, $post); if ($key === null) { // Field does not exist diff --git a/src/FieldInterface.php b/src/FieldInterface.php index ee83206..9d4d280 100644 --- a/src/FieldInterface.php +++ b/src/FieldInterface.php @@ -5,16 +5,15 @@ use Corcel\Post; /** - * Interface FieldInterface + * Interface FieldInterface. * - * @package Corcel\Acf * @author Junior Grossi */ interface FieldInterface { /** * @param string $fieldName - * @param Post $post + * @param Post $post */ public function process($fieldName, Post $post); diff --git a/tests/BasicFieldsTest.php b/tests/BasicFieldsTest.php index 958eed4..e62cae6 100644 --- a/tests/BasicFieldsTest.php +++ b/tests/BasicFieldsTest.php @@ -4,7 +4,7 @@ use Corcel\Post; /** - * Class BasicFieldTest + * Class BasicFieldTest. * * @author Junior Grossi */ @@ -16,7 +16,7 @@ class BasicFieldsTest extends PHPUnit_Framework_TestCase protected $post; /** - * Setup a base $this->post object to represent the page with the basic fields + * Setup a base $this->post object to represent the page with the basic fields. */ protected function setUp() { diff --git a/tests/ChoicesFieldsTest.php b/tests/ChoicesFieldsTest.php index 841195b..a905bad 100644 --- a/tests/ChoicesFieldsTest.php +++ b/tests/ChoicesFieldsTest.php @@ -1,12 +1,11 @@ */ @@ -17,9 +16,6 @@ class ChoicesFieldsTest extends PHPUnit_Framework_TestCase */ protected $post; - /** - * @return void - */ public function setUp() { $this->post = Post::find(44); diff --git a/tests/ContentFieldsTest.php b/tests/ContentFieldsTest.php index 7826a84..ffd601c 100644 --- a/tests/ContentFieldsTest.php +++ b/tests/ContentFieldsTest.php @@ -7,7 +7,7 @@ use Corcel\Post; /** - * Class ContentFieldsTest + * Class ContentFieldsTest. * * @author Junior Grossi */ @@ -19,7 +19,7 @@ class ContentFieldsTest extends PHPUnit_Framework_TestCase protected $post; /** - * Setup a base $this->post object to represent the page with the content fields + * Setup a base $this->post object to represent the page with the content fields. */ protected function setUp() { diff --git a/tests/CorcelIntegrationTest.php b/tests/CorcelIntegrationTest.php index 2cc08bd..a674122 100644 --- a/tests/CorcelIntegrationTest.php +++ b/tests/CorcelIntegrationTest.php @@ -1,7 +1,7 @@ */ diff --git a/tests/FieldFactoryTest.php b/tests/FieldFactoryTest.php index 17ebd55..ce85a3f 100644 --- a/tests/FieldFactoryTest.php +++ b/tests/FieldFactoryTest.php @@ -1,11 +1,10 @@ */ diff --git a/tests/LayoutFieldsTest.php b/tests/LayoutFieldsTest.php index 6240563..3283a5b 100644 --- a/tests/LayoutFieldsTest.php +++ b/tests/LayoutFieldsTest.php @@ -3,7 +3,7 @@ use Corcel\Acf\Field\Repeater; /** - * Class LayoutFieldsTest + * Class LayoutFieldsTest. * * @author Junior Grossi */ diff --git a/tests/RelationalFieldsTest.php b/tests/RelationalFieldsTest.php index 3ec3bc8..baef2b1 100644 --- a/tests/RelationalFieldsTest.php +++ b/tests/RelationalFieldsTest.php @@ -7,7 +7,7 @@ use Corcel\Post; /** - * Class RelationalFieldsTests + * Class RelationalFieldsTests. * * @author Junior Grossi */ diff --git a/tests/config/bootstrap.php b/tests/config/bootstrap.php index bea1e64..6b46dfc 100644 --- a/tests/config/bootstrap.php +++ b/tests/config/bootstrap.php @@ -3,8 +3,7 @@ /** * @author Junior Grossi */ - -require __DIR__ . '/../../vendor/autoload.php'; +require __DIR__.'/../../vendor/autoload.php'; $capsule = \Corcel\Database::connect($params = [ 'database' => 'corcel_acf',