From 686806cb9de4367090f48ca61a111a81bba49fdc Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Thu, 8 Oct 2015 17:28:17 +0100 Subject: [PATCH 001/210] Resolved issue #55, now you can access to extra params through properties or array --- src/Notifynder/Models/Notification.php | 10 ++ src/Notifynder/Notifications/ExtraParams.php | 150 ++++++++++++++++++ src/Notifynder/Parsers/NotifynderParser.php | 5 +- tests/factories/factories.php | 2 +- tests/integration/Notifable/NotifableTest.php | 0 .../Notifications/NotifynderTest.php | 8 +- .../NotificationRepositoryDBTest.php | 6 +- 7 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 src/Notifynder/Notifications/ExtraParams.php mode change 100644 => 100755 tests/integration/Notifable/NotifableTest.php diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 3a3f886..5f0fc35 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -1,5 +1,6 @@ parse($this); } + + /** + * @param $value + * @return mixed|string + */ + public function getExtraAttribute($value) + { + return new ExtraParams(json_decode($value)); + } } diff --git a/src/Notifynder/Notifications/ExtraParams.php b/src/Notifynder/Notifications/ExtraParams.php new file mode 100644 index 0000000..1bc5878 --- /dev/null +++ b/src/Notifynder/Notifications/ExtraParams.php @@ -0,0 +1,150 @@ +isJson($extraParams)) { + $this->extraParams = json_decode($extraParams,true); + } + else { + $this->extraParams = (array) $extraParams; + } + } + + /** + * @return string + */ + public function toJson() + { + return json_encode($this->extraParams); + } + + /** + * @return array + */ + public function toArray() + { + // Already possible json + if ($this->isJson($this->extraParams)) { + return json_decode($this->extraParams, true); + } + + return $this->extraParams; + } + + /** + * The __toString method allows a class to decide how it will react when it is converted to a string. + * + * @return string + */ + function __toString() + { + $extraParams = $this->extraParams; + + if (is_array($extraParams) || $extraParams instanceof stdClass) { + return $this->toJson(); + } + + return $extraParams; + } + + /** + * Check if the extra param + * exists + * + * @param $name + * @return bool + */ + public function has($name) + { + $arr = $this->extraParams; + + return isset($arr[$name]); + } + + /** + * is utilized for reading data from inaccessible members. + * + * @param $name string + * @return mixed + */ + function __get($name) + { + $params = $this->toArray(); + + return $params[$name]; + } + + + /** + * Whether a offset exists + * + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset) + { + return $this->has($offset); + } + + /** + * @param mixed $offset + * @return mixed Can return all value types. + */ + public function offsetGet($offset) + { + return $this->extraParams[$offset]; + } + + /** + * @param mixed $offset + * @param mixed $value + */ + public function offsetSet($offset, $value) + { + $this->extraParams[$offset] = $value; + } + + /** + * @param mixed $offset + */ + public function offsetUnset($offset) + { + unset($this->extraParams[$offset]); + } + + /** + * Check if the value + * is a json string + * + * @param $value + * @return bool + */ + public function isJson($value) + { + if (!is_string($value)) return false; + + json_decode($value); + return (json_last_error() == JSON_ERROR_NONE); + } +} \ No newline at end of file diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index 873f1f1..c5960bf 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -26,7 +26,7 @@ public function parse($item) $extra = $item['extra']; // Decode the data passed into an array - $extra = json_decode($extra); + //$extra = json_decode($extra); $specialValues = $this->getValues($body); if ($specialValues > 0) { @@ -89,7 +89,8 @@ protected function replaceExtraValues($extrasToReplace, $extra, $body) foreach ($extrasToReplace as $replacer) { $valueMatch = explode('.', $replacer)[1]; - if (array_key_exists($valueMatch, $extra)) { + + if ($extra->has($valueMatch)) { $body = str_replace('{'.$replacer.'}', $extra->{$valueMatch}, $body); } diff --git a/tests/factories/factories.php b/tests/factories/factories.php index 84fffdb..acf1bf6 100755 --- a/tests/factories/factories.php +++ b/tests/factories/factories.php @@ -21,7 +21,7 @@ 'to_type' => 'Fenos\Tests\Models\User', 'category_id' => 'factory:Fenos\Notifynder\Models\NotificationCategory', 'url' => $faker->url, - 'extra' => $faker->name, + 'extra' => json_encode(['exta.name' => $faker->name]), 'read' => 0, 'expire_time' => null, 'created_at' => $faker->dateTime, diff --git a/tests/integration/Notifable/NotifableTest.php b/tests/integration/Notifable/NotifableTest.php old mode 100644 new mode 100755 diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php index 2d7c433..8c6be3d 100755 --- a/tests/integration/Notifications/NotifynderTest.php +++ b/tests/integration/Notifications/NotifynderTest.php @@ -89,12 +89,14 @@ function it_send_using_notifynder_as_an_object() $this->assertEquals('w',$notification->url); } - /** @test */ + /** + * @test + */ function it_store_extra_field_as_json() { $this->createCategory(['name' => 'custom']); - $extra = ['notifynder' => 'amazing']; + $extra = ['extra.name' => 'amazing']; $notifications = $this->notifynder ->category('custom') @@ -104,7 +106,7 @@ function it_store_extra_field_as_json() ->to(1); $notifications = $this->notifynder->send($notifications); - $this->assertEquals(json_encode($extra),$notifications->extra); + $this->assertEquals($notifications->extra->toArray(),$extra); } /** diff --git a/tests/integration/Repositories/NotificationRepositoryDBTest.php b/tests/integration/Repositories/NotificationRepositoryDBTest.php index 9f17ba6..01c3de4 100755 --- a/tests/integration/Repositories/NotificationRepositoryDBTest.php +++ b/tests/integration/Repositories/NotificationRepositoryDBTest.php @@ -62,12 +62,14 @@ function it_send_a_single_notification() $this->assertEquals($notificationToSend['to_type'],$notification->to_type); } - /** @test */ + /** @test + * @group fails + */ function it_send_multiple_notification() { $notificationsToSend[0] = $this->buildNotification(); $notificationsToSend[1] = $this->buildNotification(); - + //dd($notificationsToSend); $storeMultipleNotificaations = $this->notificationRepo->storeMultiple($notificationsToSend); $notifications = Notification::all(); From 1f973ef967d3a97e4f57dd2027c4c4fb07a6b7a7 Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Thu, 8 Oct 2015 18:51:38 +0100 Subject: [PATCH 002/210] Adding strict_extra config option for this use case. when enabled, Throw Exception when extra param it's missing. When Disabled will just strip out the {extra} markup from the text parsed, #54 --- .../Parsers/NotifynderParserSpec.php | 42 ++++++ .../Exceptions/ExtraParamsException.php | 8 ++ src/Notifynder/NotifynderServiceProvider.php | 6 + src/Notifynder/Parsers/NotifynderParser.php | 121 ++++++++++++++++-- src/config/notifynder.php | 10 ++ 5 files changed, 176 insertions(+), 11 deletions(-) create mode 100644 src/Notifynder/Exceptions/ExtraParamsException.php diff --git a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php index d641a5e..1a46284 100755 --- a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php +++ b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php @@ -2,6 +2,8 @@ namespace spec\Fenos\Notifynder\Parsers; +use Fenos\Notifynder\Exceptions\ExtraParamsException; +use Fenos\Notifynder\Parsers\NotifynderParser; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -60,4 +62,44 @@ function it_replace_both_in_a_string() $this->parse($notification)->shouldReturn('Hi jhon hello world'); } + + /** @test */ + function it_will_remove_extra_markup_if_extra_value_is_not_provided() + { + $extra = []; + + $notification = [ + 'body' => [ + 'text' => 'Hi {to.username} hello {extra.hello}' + ], + 'to' => [ + 'username' => 'jhon', + ], + 'extra' => json_encode($extra) + ]; + + // note the space, TODO: shall i remove it? + $this->parse($notification)->shouldReturn('Hi jhon hello '); + } + + /** @test */ + function it_will_throw_exception_when_strict_extra_is_enabled() + { + $extra = null; + + $notification = [ + 'body' => [ + 'text' => 'Hi {to.username} hello {extra.hello}' + ], + 'to' => [ + 'username' => 'jhon', + ], + 'extra' => json_encode($extra) + ]; + + NotifynderParser::setStrictExtra(true); + + $this->shouldThrow(ExtraParamsException::class) + ->during('parse',[$notification]); + } } diff --git a/src/Notifynder/Exceptions/ExtraParamsException.php b/src/Notifynder/Exceptions/ExtraParamsException.php new file mode 100644 index 0000000..3d4926e --- /dev/null +++ b/src/Notifynder/Exceptions/ExtraParamsException.php @@ -0,0 +1,8 @@ + config_path('notifynder.php'), __DIR__.'/../migrations/' => base_path('/database/migrations'), ]); + + // Set use strict_extra config option, + // you can toggle it in the configuraiton file + $strictParam = $this->app['config']->get('notifynder.strict_extra',false); + NotifynderParser::setStrictExtra($strictParam); } /** diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index c5960bf..e24b4e8 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -1,17 +1,28 @@ 0) { - list($extrasToReplace, $relationsToReplace) = $this->categorizeSpecialValues($specialValues); + list($extractedExtra, $relationsToReplace) = $this->categorizeSpecialValues($specialValues); - $body = $this->replaceExtraValues($extrasToReplace, $extra, $body); + $body = $this->replaceExtraValues($extractedExtra, $extraParam, $body); $body = $this->replaceValuesRelations($item, $relationsToReplace, $body); } return $body; } + /** + * Set strict mode. + * if it's enabled then will throws exceptions + * when extra params will not be parsed correctly + * will be handy in development + * + * @param bool|true $set + */ + public static function setStrictExtra($set = true) + { + static::$strictMode = $set; + } + /** * I categorize into 2 arrays * the relations values @@ -71,16 +95,14 @@ protected function categorizeSpecialValues($specialValues) /** * This method replace extra values - * of the given extra values specified - * in the extra field of the notification - * (parsed from Json) I use a convention - * to keep all the extras values under - * an {extra.*} namespace + * within the {extra.*} namespace. + * * * @param $extrasToReplace * @param $extra * @param $body * @return array + * @throws ExtraParamsException */ protected function replaceExtraValues($extrasToReplace, $extra, $body) { @@ -89,10 +111,33 @@ protected function replaceExtraValues($extrasToReplace, $extra, $body) foreach ($extrasToReplace as $replacer) { $valueMatch = explode('.', $replacer)[1]; + // Whichever type i + $extra = $this->extraToArray($extra); + + // Let's cover the scenario where the developer + // forget to add the extra param to a category that it's + // needed. Ex: caterogy name:"hi" text:"hello {extra.name}" + // developer store the notification without passing the value to extra + // into the db will be NULL. This will just remove the {extra.hello}. + // In production it's better a "typo" mistake in the text then an Exception. + // however we can force to throw an Exception for development porpose + // NotifynderParser::setExtraStrict(true); + if ( !is_array($extra) or (is_array($extra) and count($extra) == 0) ) { + + $body = $this->replaceBody($body, '', $replacer); + + // In strict mode you'll be aware + if (static::$strictMode) { + $error = "the following [$replacer] param required from your category it's missing. Did you forget to store it?"; + throw new ExtraParamsException($error); + } + + break; + } - if ($extra->has($valueMatch)) { + if (array_key_exists($valueMatch, $extra)) { - $body = str_replace('{'.$replacer.'}', $extra->{$valueMatch}, $body); + $body = $this->replaceBody($body, $extra[$valueMatch], $replacer); } } @@ -138,4 +183,58 @@ protected function getValues($body) return $values[1]; } + + /** + * Trying to transform extra in from few datatypes + * to array type + * + * @param $extra + * @return array|mixed + */ + protected function extraToArray($extra) + { + if ($this->isJson($extra)) { + + $extra = json_decode($extra, true); + return $extra; + + } else if ($extra instanceof ExtraParams) { + $extra = $extra->toArray(); + return $extra; + } + + return null; + } + + /** + * Replace body of the category + * + * @param $body + * @param $replacer + * @param $valueMatch + * @return mixed + */ + protected function replaceBody($body, $valueMatch, $replacer) + { + $body = str_replace('{'.$replacer.'}', $valueMatch, $body); + + return $body; + } + + /** + * Check if is a json string + * + * @param $value + * @return bool + */ + protected function isJson($value) + { + if ( ! is_string($value)) { + return false; + } + + json_decode($value); + + return (json_last_error() == JSON_ERROR_NONE); + } } \ No newline at end of file diff --git a/src/config/notifynder.php b/src/config/notifynder.php index 5d6702f..eca6c64 100755 --- a/src/config/notifynder.php +++ b/src/config/notifynder.php @@ -29,6 +29,16 @@ */ 'notification_model' => 'Fenos\Notifynder\Models\Notification', + /** + * Coordinating a lots notifications that require extra params + * might cause to forget and not insert the {extra.*} value needed. + * This flag allow you to cause an exception to be thrown if you miss + * to store a extra param that the category will need. + * NOTE: use only in development. + * WHEN DISABLED: will just remove the {extra.*} markup from the sentence + */ + 'strict_extra' => false, + /** * If you wish to have the translations in a specific file * just require the file on the following option. From 5bdd1cf9980998fa10f8c2e2680994df51e866af Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Thu, 8 Oct 2015 20:34:44 +0100 Subject: [PATCH 003/210] Now it's possible to add custom query filters from get methods, the category scope has been added to solve the common query of the issue #50 --- .../Notifications/NotificationManagerSpec.php | 10 +- .../Parsers/NotifynderParserSpec.php | 2 +- src/Notifynder/Contracts/NotificationDB.php | 80 ++++---- .../Contracts/NotifynderNotification.php | 24 ++- src/Notifynder/Models/Notification.php | 19 ++ src/Notifynder/Notifable.php | 36 ++-- .../Notifications/NotificationManager.php | 50 +++-- .../Notifications/NotificationRepository.php | 179 +++++++++++------- src/Notifynder/Notifynder.php | 19 +- src/Notifynder/NotifynderManager.php | 47 +++-- .../Notifications/NotificationTest.php | 22 +++ tests/models/User.php | 2 + 12 files changed, 306 insertions(+), 184 deletions(-) diff --git a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php b/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php index 0ad4550..6cca115 100755 --- a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php +++ b/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php @@ -129,7 +129,7 @@ function it_get_not_read_notification(NotificationDB $notificationRepo,Notifynde $limit = 10; $paginate = null; - $notificationRepo->getNotRead($entity_id,null,$limit,$paginate,'desc')->shouldBeCalled() + $notificationRepo->getNotRead($entity_id,null,$limit,$paginate,'desc',null)->shouldBeCalled() ->willReturn($collection); $collection->parse()->shouldBeCalled()->willReturn([]); @@ -144,7 +144,7 @@ function it_get_all_notifications_of_the_given_entity(NotificationDB $notificati $limit = 10; $paginate = null; - $notificationRepo->getAll($entity_id,null,$limit,$paginate,'desc')->shouldBeCalled() + $notificationRepo->getAll($entity_id,null,$limit,$paginate,'desc',null)->shouldBeCalled() ->willReturn($collection); $collection->parse()->shouldBeCalled()->willReturn([]); @@ -157,7 +157,7 @@ function it_get_last_notification_of_the_current_entity(NotificationDB $notifica { $id = 1; - $notificationRepo->getLastNotification($id,null)->shouldBeCalled()->willReturn(new Notification()); + $notificationRepo->getLastNotification($id,null,null)->shouldBeCalled()->willReturn(new Notification()); $this->getLastNotification($id)->shouldReturnAnInstanceOf(Notification::class); } @@ -168,7 +168,7 @@ function it_get_last_notification_of_the_current_entity_filtering_by_category(No $id = 1; $category = 'notifynder.category'; - $notificationRepo->getLastNotificationByCategory($category,$id,null)->shouldBeCalled()->willReturn(new Notification()); + $notificationRepo->getLastNotificationByCategory($category,$id,null,null)->shouldBeCalled()->willReturn(new Notification()); $this->getLastNotificationByCategory($category,$id)->shouldReturnAnInstanceOf(Notification::class); } @@ -203,7 +203,7 @@ function it_count_notification_not_read(NotificationDB $notificationRepo) $entity_id = 1; $notificationCount = 10; - $notificationRepo->countNotRead($entity_id,null)->shouldBeCalled() + $notificationRepo->countNotRead($entity_id,null,null)->shouldBeCalled() ->willReturn($notificationCount); $this->countNotRead($entity_id)->shouldReturn($notificationCount); diff --git a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php index 1a46284..ddda0a1 100755 --- a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php +++ b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php @@ -102,4 +102,4 @@ function it_will_throw_exception_when_strict_extra_is_enabled() $this->shouldThrow(ExtraParamsException::class) ->during('parse',[$notification]); } -} +} \ No newline at end of file diff --git a/src/Notifynder/Contracts/NotificationDB.php b/src/Notifynder/Contracts/NotificationDB.php index 9b4a564..152f60e 100755 --- a/src/Notifynder/Contracts/NotificationDB.php +++ b/src/Notifynder/Contracts/NotificationDB.php @@ -1,5 +1,6 @@ where('category_id',$category); + } + + return $query->whereHas('body', function($categoryQuery) use ($category) { + $categoryQuery->where('name',$category); + }); + } } diff --git a/src/Notifynder/Notifable.php b/src/Notifynder/Notifable.php index c9d896a..1b14089 100755 --- a/src/Notifynder/Notifable.php +++ b/src/Notifynder/Notifable.php @@ -1,5 +1,7 @@ notifynderInstance()->entity( $this->getMorphClass() - )->getNotRead($this->id, $limit, $paginate, $order); + )->getNotRead($this->id, $limit, $paginate, $order,$filterScope); } /** * Get all notifications * - * @param null $limit - * @param int|null $paginate - * @param string $order + * @param null $limit + * @param int|null $paginate + * @param string $order + * @param Closure $filterScope * @return mixed */ - public function getNotifications($limit = null, $paginate = null, $order = 'desc') + public function getNotifications($limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) { return $this->notifynderInstance()->entity( $this->getMorphClass() - )->getAll($this->id, $limit, $paginate, $order); + )->getAll($this->id, $limit, $paginate, $order, $filterScope); } /** * Get last notification * - * @param null $category + * @param null $category + * @param Closure $filterScope * @return mixed */ - public function getLastNotification($category = null) + public function getLastNotification($category = null,Closure $filterScope = null) { return $this->notifynderInstance()->entity( $this->getMorphClass() - )->getLastNotification($this->id,$category); + )->getLastNotification($this->id,$category,$filterScope); } /** * Count Not read notification * + * @param Closure $filterScope * @return mixed */ - public function countNotificationsNotRead() + public function countNotificationsNotRead(Closure $filterScope = null) { return $this->notifynderInstance()->entity( $this->getMorphClass() - )->countNotRead($this->id); + )->countNotRead($this->id,$filterScope); } /** diff --git a/src/Notifynder/Notifications/NotificationManager.php b/src/Notifynder/Notifications/NotificationManager.php index bffbca5..53a4a36 100755 --- a/src/Notifynder/Notifications/NotificationManager.php +++ b/src/Notifynder/Notifications/NotificationManager.php @@ -1,5 +1,6 @@ notifynderRepo->getNotRead( $to_id, $this->entity, - $limit, $paginate, $orderDate + $limit, $paginate, $orderDate, + $filterScope ); - if(is_int(intval($paginate)) && !is_null($paginate)) + if(is_int(intval($paginate)) && $paginate) { return (new Paginator($notifications->parse(), $limit, $paginate, [ 'path' => Paginator::resolveCurrentPath(), @@ -189,20 +192,22 @@ public function getNotRead($to_id, $limit = null, $paginate = null, $orderDate = /** * Get All notifications * - * @param $to_id - * @param $limit + * @param $to_id + * @param $limit * @param int|null $paginate - * @param string $orderDate + * @param string $orderDate + * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'desc') + public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) { $notifications = $this->notifynderRepo->getAll( $to_id, $this->entity, - $limit, $paginate, $orderDate + $limit, $paginate, $orderDate, + $filterScope ); - if(is_int(intval($paginate)) && !is_null($paginate)) + if(is_int(intval($paginate)) && $paginate) { return (new Paginator($notifications->parse(), $limit, $paginate, [ 'path' => Paginator::resolveCurrentPath(), @@ -216,25 +221,27 @@ public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'de * Get last notification of the * given entity * - * @param $to_id + * @param $to_id + * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id) + public function getLastNotification($to_id, Closure $filterScope = null) { - return $this->notifynderRepo->getLastNotification($to_id,$this->entity); + return $this->notifynderRepo->getLastNotification($to_id,$this->entity,$filterScope); } /** * Get last notification of the * given entity of the specific category * - * @param $category - * @param $to_id + * @param $category + * @param $to_id + * @param Closure $filterScope * @return mixed */ - public function getLastNotificationByCategory($category,$to_id) + public function getLastNotificationByCategory($category,$to_id, Closure $filterScope = null) { - return $this->notifynderRepo->getLastNotificationByCategory($category,$to_id,$this->entity); + return $this->notifynderRepo->getLastNotificationByCategory($category,$to_id,$this->entity,$filterScope); } /** @@ -263,10 +270,11 @@ public function sendMultiple(array $info) * Get number of notification * not read * - * @param $to_id + * @param $to_id + * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id) + public function countNotRead($to_id, Closure $filterScope = null) { return $this->notifynderRepo->countNotRead($to_id, $this->entity); } diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index 48af0af..5e31804 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -1,7 +1,7 @@ notification = $notification; $this->db = $db; } @@ -51,7 +52,7 @@ public function find($notification_id) /** * Save a single notification sent * - * @param array $info + * @param array $info * @return Notification */ public function storeSingle(array $info) @@ -76,7 +77,7 @@ public function storeMultiple(array $info) /** * Make Read One Notification * - * @param Notification $notification + * @param Notification $notification * @return bool|Notification */ public function readOne(Notification $notification) @@ -109,7 +110,7 @@ public function readLimit($to_id, $entity, $numbers, $order) ->lists('id'); return $this->notification->whereIn('id', $notifications) - ->update(['read' => 1]); + ->update(['read' => 1]); } /** @@ -148,12 +149,12 @@ public function delete($notification_id) */ public function deleteAll($to_id, $entity) { - $query = $this->db->table( + $query = $this->db->table( $this->notification->getTable() ); return $this->notification->scopeWherePolymorphic($query, $to_id, $entity) - ->delete(); + ->delete(); } /** @@ -161,14 +162,17 @@ public function deleteAll($to_id, $entity) * defined category * * @param $category_name int - * @param $expired Bool + * @param $expired Bool * @return Bool */ public function deleteByCategory($category_name, $expired = false) { - $query = $this->notification->whereHas('body', function ($q) use ($category_name) { - $q->where('name', $category_name); - }); + $query = $this->notification->whereHas( + 'body', + function ($q) use ($category_name) { + $q->where('name', $category_name); + } + ); if ($expired == true) { return $query->onlyExpired()->delete(); @@ -196,14 +200,15 @@ public function deleteLimit($user_id, $entity, $number, $order) ->wherePolymorphic($user_id, $entity) ->orderBy('id', $order) ->select('id') - ->limit($number)->lists('id'); + ->limit($number) + ->lists('id'); if (count($notifications_ids) == 0) { return false; } return $this->notification->whereIn('id', $notifications_ids) - ->delete(); + ->delete(); } /** @@ -211,31 +216,39 @@ public function deleteLimit($user_id, $entity, $number, $order) * You can also limit the number of * Notification if you don't it will get all * - * @param $to_id - * @param $entity - * @param int|null $limit - * @param int|null $paginate - * @param string $orderDate + * @param $to_id + * @param $entity + * @param int|null $limit + * @param int|null $paginate + * @param string $orderDate + * @param Closure|null $filterScope * @return mixed */ - public function getNotRead($to_id, $entity, $limit = null, $paginate = null, $orderDate = 'desc') - { - $result = $this->notification->with('body', 'from') + public function getNotRead( + $to_id, + $entity, + $limit = null, + $paginate = null, + $orderDate = 'desc', + Closure $filterScope = null + ) { + $query = $this->notification->with('body', 'from') ->wherePolymorphic($to_id, $entity) ->withNotRead() ->orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); - if (! is_null($limit)) { - $result->limit($limit); + $query = $this->applyFilter($filterScope, $query); + + if ( is_int($limit)) { + $query->limit($limit); } - if(is_int(intval($paginate)) && !is_null($paginate)) - { - $result->skip(($paginate - 1) * $limit)->take($limit + 1); + if (is_int(intval($paginate)) && $paginate) { + $query->skip(($paginate - 1) * $limit)->take($limit + 1); } - return $result->get(); + return $query->get(); } /** @@ -244,85 +257,117 @@ public function getNotRead($to_id, $entity, $limit = null, $paginate = null, $or * You can also limit the number of * Notifications if you don't, it will get all * - * @param $to_id - * @param $entity - * @param null $limit - * @param int|null $paginate - * @param string $orderDate + * @param $to_id + * @param $entity + * @param null $limit + * @param int|null $paginate + * @param string $orderDate + * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $entity, $limit = null, $paginate = null, $orderDate = 'desc') - { - $result = $this->notification->with('body', 'from') + public function getAll( + $to_id, + $entity, + $limit = null, + $paginate = null, + $orderDate = 'desc', + Closure $filterScope = null + ) { + $query = $this->notification->with('body', 'from') ->wherePolymorphic($to_id, $entity) ->orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); + $query = $this->applyFilter($filterScope, $query); + + // if the limit is set - if (! is_null($limit)) { - $result->limit($limit); + if ( is_int($limit)) { + $query->limit($limit); } - if(is_int(intval($paginate)) && !is_null($paginate)) - { - $result->skip(($paginate - 1) * $limit)->take($limit + 1); + if (is_int(intval($paginate)) && $paginate) { + $query->skip(($paginate - 1) * $limit)->take($limit + 1); } - return $result->get(); + return $query->get(); } /** * get number Notifications * not read * - * @param $to_id - * @param $entity + * @param $to_id + * @param $entity + * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id, $entity) + public function countNotRead($to_id, $entity, Closure $filterScope = null) { - return $this->notification->wherePolymorphic($to_id, $entity) + $query = $this->notification->wherePolymorphic($to_id, $entity) ->withNotRead() - ->select($this->db->raw('Count(*) as notRead')) - ->count(); + ->select($this->db->raw('Count(*) as notRead')); + + $query = $this->applyFilter($filterScope, $query); + + return $query->count(); } /** * Get last notification of the current * entity * - * @param $to_id - * @param $entity + * @param $to_id + * @param $entity + * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id,$entity) + public function getLastNotification($to_id, $entity, Closure $filterScope = null) { - return $this->notification->wherePolymorphic($to_id, $entity) - ->orderBy('created_at','DESC') - ->first(); + $query = $this->notification->wherePolymorphic($to_id, $entity) + ->orderBy('created_at', 'DESC'); + + $query = $this->applyFilter($filterScope, $query); + + return $query->first(); } /** * Get last notification of the current * entity of a specific category * - * @param $category - * @param $to_id - * @param $entity + * @param $category + * @param $to_id + * @param $entity + * @param Closure $filterScope * @return mixed */ - public function getLastNotificationByCategory($category,$to_id,$entity) + public function getLastNotificationByCategory($category, $to_id, $entity, Closure $filterScope = null) { - $query = $this->notification->wherePolymorphic($to_id, $entity); + $query = $this->notification + ->wherePolymorphic($to_id, $entity) + ->byCategory($category) + ->orderBy('created_at', 'desc'); - if (is_numeric($category)) { + $query = $this->applyFilter($filterScope, $query); + + return $query->first(); + } - return $query->orderBy('created_at','desc') - ->where('category_id',$category)->first(); + /** + * Apply scope filters + * + * @param Closure $filterScope + * @param $query + */ + protected function applyFilter(Closure $filterScope = null, $query) + { + if ( ! $filterScope) { + return $query; } - return $query->whereHas('body', function($categoryQuery) use ($category) { - $categoryQuery->where('name',$category); - })->orderBy('created_at','desc')->first(); + $filterScope($query); + + return $query; } } diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php index f0f3cd1..2c01585 100755 --- a/src/Notifynder/Notifynder.php +++ b/src/Notifynder/Notifynder.php @@ -1,5 +1,6 @@ notification->entity($this->entity); - return $notifications->getNotRead($to_id, $limit, $paginate, $order); + return $notifications->getNotRead($to_id, $limit, $paginate, $order, $filterScope); } /** * Get all notifications of the * given entity * - * @param $to_id - * @param null $limit - * @param int|null $paginate - * @param string $order + * @param $to_id + * @param null $limit + * @param int|null $paginate + * @param string $order + * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $limit = null, $paginate = null, $order = "desc") + public function getAll($to_id, $limit = null, $paginate = null, $order = "desc", Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); - return $notifications->getAll($to_id, $limit, $paginate); + return $notifications->getAll($to_id, $limit, $paginate,$order, $filterScope); } /** * Get number of notification not read * of the given entity * - * @param $to_id + * @param $to_id + * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id) + public function countNotRead($to_id,Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); - return $notifications->countNotRead($to_id); + return $notifications->countNotRead($to_id,$filterScope); } /** @@ -402,19 +406,20 @@ public function findNotificationById($notification_id) * entity, second parameter can filter by * category * - * @param $to_id - * @param null $category + * @param $to_id + * @param null $category + * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id,$category = null) + public function getLastNotification($to_id,$category = null,Closure $filterScope = null) { $notification = $this->notification->entity($this->entity); if ( is_null($category)) { - return $notification->getLastNotification($to_id); + return $notification->getLastNotification($to_id,$filterScope); } - return $notification->getLastNotificationByCategory($category,$to_id); + return $notification->getLastNotificationByCategory($category,$to_id,$filterScope); } /** diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 138ce49..ed96d9c 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -80,4 +80,26 @@ function it_retrieve_notification_by_paginating_the_number() $bodyParsed = 'parse this Amazing value'; $this->assertEquals($bodyParsed,$notifications->items()[0]->text); } + + /** + * It will query adding the filter scope + * on of the category by name + * + * @test + */ + function it_will_query_for_notification_by_category_name() + { + app('config')->set('notifynder.polymorphic',false); + $this->createMultipleNotifications(); + $category = $this->createCategory(['text' => 'parse this {extra.look} value','name' => 'text']); + $this->createMultipleNotifications(['category_id' => $category->id]); + + $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); + + $notificationByCategory = $user->getNotifications(false,false,'desc', function($query) use ($category) { + $query->byCategory('text'); + }); + + $this->assertCount(10,$notificationByCategory); + } } \ No newline at end of file diff --git a/tests/models/User.php b/tests/models/User.php index ddfb764..76a861b 100755 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -4,5 +4,7 @@ class User extends \Illuminate\Database\Eloquent\Model { + // Never do this + protected $fillable = ['id']; use Notifable; } \ No newline at end of file From 73d258048ed8aab6b221cf833525884fd1c89089 Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Fri, 9 Oct 2015 21:00:06 +0100 Subject: [PATCH 004/210] fixed versioning --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3641546..b0d88a6 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Notifynder 3.0 - Laravel 5 +Notifynder 3.1 - Laravel 5 ========== [![Build Status](https://travis-ci.org/fenos/Notifynder.svg?branch=master)](https://travis-ci.org/fenos/Notifynder) @@ -25,7 +25,7 @@ Documentation: **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)** Add it on your composer.json ~~~ -"fenos/notifynder": "3.*" +"fenos/notifynder": "3.1.*" ~~~ and run **composer update** From dc01c005702fc871e215d61b65a72b4e69ce250f Mon Sep 17 00:00:00 2001 From: Oliver Kaufmann Date: Fri, 16 Oct 2015 10:42:57 +0200 Subject: [PATCH 005/210] Move extracting of extra data out of the foreach --- src/Notifynder/Parsers/NotifynderParser.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index e24b4e8..4b2cfd1 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -107,13 +107,14 @@ protected function categorizeSpecialValues($specialValues) protected function replaceExtraValues($extrasToReplace, $extra, $body) { // replace the values specified in the extra + + // Whichever type i + $extra = $this->extraToArray($extra); + // wildcard foreach ($extrasToReplace as $replacer) { $valueMatch = explode('.', $replacer)[1]; - // Whichever type i - $extra = $this->extraToArray($extra); - // Let's cover the scenario where the developer // forget to add the extra param to a category that it's // needed. Ex: caterogy name:"hi" text:"hello {extra.name}" From 8ea6ba0d14840a7a599c7449722c91a6cf08c4bd Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Fri, 16 Oct 2015 15:22:52 +0100 Subject: [PATCH 006/210] Tested PR --- .../Parsers/NotifynderParserSpec.php | 22 +++++++++++++++++++ src/Notifynder/Parsers/NotifynderParser.php | 5 ++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php index ddda0a1..756cfb9 100755 --- a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php +++ b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php @@ -102,4 +102,26 @@ function it_will_throw_exception_when_strict_extra_is_enabled() $this->shouldThrow(ExtraParamsException::class) ->during('parse',[$notification]); } + + /** @test */ + function it_will_parse_4_extra_params() + { + $extra = [ + 'name' => 'fabri', + 'username' => 'fenos', + 'status' => 'active', + 'prof' => 'dev' + ]; + + $text = 'Hi {extra.name}, your username is: {extra.username} your status: {extra.status} your profession: {extra.prof}'; + $notification = [ + 'body' => [ + 'text' => $text + ], + 'extra' => json_encode($extra) + ]; + + $parsedText = "Hi {$extra['name']}, your username is: {$extra['username']} your status: {$extra['status']} your profession: {$extra['prof']}"; + $this->parse($notification)->shouldReturn($parsedText); + } } \ No newline at end of file diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index 4b2cfd1..eb3010a 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -106,9 +106,8 @@ protected function categorizeSpecialValues($specialValues) */ protected function replaceExtraValues($extrasToReplace, $extra, $body) { - // replace the values specified in the extra - - // Whichever type i + // I'll try my best to have returned the + // extra param as an array $extra = $this->extraToArray($extra); // wildcard From 3199f39e5a20d6a2e6c4e861045f7ce48505e316 Mon Sep 17 00:00:00 2001 From: Oliver Kaufmann Date: Tue, 22 Dec 2015 09:07:59 +0100 Subject: [PATCH 007/210] Change bindShared to singleton due to deprecation since Laravel 5.1 --- src/Notifynder/NotifynderServiceProvider.php | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 553527c..0192af4 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -68,7 +68,7 @@ public function boot() */ protected function notifynder() { - $this->app->bindShared('notifynder', function ($app) { + $this->app->singleton('notifynder', function ($app) { return new NotifynderManager( $app['notifynder.category'], $app['notifynder.sender'], @@ -87,13 +87,13 @@ protected function notifynder() */ protected function categories() { - $this->app->bindShared('notifynder.category', function ($app) { + $this->app->singleton('notifynder.category', function ($app) { return new CategoryManager( $app->make('notifynder.category.repository') ); }); - $this->app->bindShared('notifynder.category.repository', function ($app) { + $this->app->singleton('notifynder.category.repository', function ($app) { return new CategoryRepository( new NotificationCategory() ); @@ -105,13 +105,13 @@ protected function categories() */ protected function notifications() { - $this->app->bindShared('notifynder.notification', function ($app) { + $this->app->singleton('notifynder.notification', function ($app) { return new NotificationManager( $app['notifynder.notification.repository'] ); }); - $this->app->bindShared('notifynder.notification.repository', function ($app) { + $this->app->singleton('notifynder.notification.repository', function ($app) { $notificationModel = $app['config']->get('notifynder.notification_model'); $notificationIstance = $app->make($notificationModel); @@ -131,14 +131,14 @@ protected function notifications() */ protected function translator() { - $this->app->bindShared('notifynder.translator', function ($app) { + $this->app->singleton('notifynder.translator', function ($app) { return new TranslatorManager( $app['notifynder.translator.compiler'], $app['config'] ); }); - $this->app->bindShared('notifynder.translator.compiler', function ($app) { + $this->app->singleton('notifynder.translator.compiler', function ($app) { return new Compiler( $app['filesystem.disk'] ); @@ -150,7 +150,7 @@ protected function translator() */ protected function senders() { - $this->app->bindShared('notifynder.sender', function ($app) { + $this->app->singleton('notifynder.sender', function ($app) { return new SenderManager( $app['notifynder.sender.factory'], $app['notifynder.store'], @@ -158,7 +158,7 @@ protected function senders() ); }); - $this->app->bindShared('notifynder.sender.factory', function ($app) { + $this->app->singleton('notifynder.sender.factory', function ($app) { return new SenderFactory( $app['notifynder.group'], $app['notifynder.category'] @@ -171,7 +171,7 @@ protected function senders() */ protected function events() { - $this->app->bindShared('notifynder.dispatcher', function ($app) { + $this->app->singleton('notifynder.dispatcher', function ($app) { return new Dispatcher( $app['events'] ); @@ -183,20 +183,20 @@ protected function events() */ protected function groups() { - $this->app->bindShared('notifynder.group', function ($app) { + $this->app->singleton('notifynder.group', function ($app) { return new GroupManager( $app['notifynder.group.repository'], $app['notifynder.group.category'] ); }); - $this->app->bindShared('notifynder.group.repository', function ($app) { + $this->app->singleton('notifynder.group.repository', function ($app) { return new GroupRepository( new NotificationGroup() ); }); - $this->app->bindShared('notifynder.group.category', function ($app) { + $this->app->singleton('notifynder.group.category', function ($app) { return new GroupCategoryRepository( $app['notifynder.category'], new NotificationGroup() @@ -209,7 +209,7 @@ protected function groups() */ protected function builder() { - $this->app->bindShared('notifynder.builder', function ($app) { + $this->app->singleton('notifynder.builder', function ($app) { return new NotifynderBuilder( $app['notifynder.category'] ); @@ -264,26 +264,26 @@ protected function config() protected function artisan() { // Categories - $this->app->bindShared('notifynder.artisan.category-add', function ($app) { + $this->app->singleton('notifynder.artisan.category-add', function ($app) { return new CreateCategory( $app['notifynder.category'] ); }); - $this->app->bindShared('notifynder.artisan.category-delete', function ($app) { + $this->app->singleton('notifynder.artisan.category-delete', function ($app) { return new DeleteCategory( $app['notifynder.category'] ); }); // Groups - $this->app->bindShared('notifynder.artisan.group-add', function ($app) { + $this->app->singleton('notifynder.artisan.group-add', function ($app) { return new CreateGroup( $app['notifynder.group'] ); }); - $this->app->bindShared('notifynder.artisan.group-add-categories', function ($app) { + $this->app->singleton('notifynder.artisan.group-add-categories', function ($app) { return new PushCategoryToGroup( $app['notifynder.group'], new ArtisanOptionsParser() From 13364f560b9ce8fb2bbbc066ac779937831f97a1 Mon Sep 17 00:00:00 2001 From: Robot Date: Mon, 28 Dec 2015 06:13:59 +0100 Subject: [PATCH 008/210] Stillmaintained , why u no working anymore ? --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b0d88a6..2ef3d30 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Notifynder 3.1 - Laravel 5 ========== [![Build Status](https://travis-ci.org/fenos/Notifynder.svg?branch=master)](https://travis-ci.org/fenos/Notifynder) -[![ProjectStatus](http://stillmaintained.com/fenos/Notifynder.png)](http://stillmaintained.com/fenos/Notifynder) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fenos/Notifynder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) [![Total Downloads](https://poser.pugx.org/fenos/notifynder/downloads.svg)](https://packagist.org/packages/fenos/notifynder) [![License](https://poser.pugx.org/fenos/Notifynder/license.png)](https://packagist.org/packages/fenos/Notifynder) From 80e4ee5aa12368ec5872eb952f0cef894a8172e7 Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Tue, 29 Dec 2015 17:46:17 +0000 Subject: [PATCH 009/210] Still maintained --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2ef3d30..b0d88a6 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Notifynder 3.1 - Laravel 5 ========== [![Build Status](https://travis-ci.org/fenos/Notifynder.svg?branch=master)](https://travis-ci.org/fenos/Notifynder) +[![ProjectStatus](http://stillmaintained.com/fenos/Notifynder.png)](http://stillmaintained.com/fenos/Notifynder) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fenos/Notifynder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) [![Total Downloads](https://poser.pugx.org/fenos/notifynder/downloads.svg)](https://packagist.org/packages/fenos/notifynder) [![License](https://poser.pugx.org/fenos/Notifynder/license.png)](https://packagist.org/packages/fenos/Notifynder) From 7cd2ea700e2c77c06b9fa67e2515a7ae02482325 Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Tue, 29 Dec 2015 18:13:04 +0000 Subject: [PATCH 010/210] Stillmaintained badge removed, website down I didn't check the commit of my collaborator before undo the badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b0d88a6..2ef3d30 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Notifynder 3.1 - Laravel 5 ========== [![Build Status](https://travis-ci.org/fenos/Notifynder.svg?branch=master)](https://travis-ci.org/fenos/Notifynder) -[![ProjectStatus](http://stillmaintained.com/fenos/Notifynder.png)](http://stillmaintained.com/fenos/Notifynder) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fenos/Notifynder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) [![Total Downloads](https://poser.pugx.org/fenos/notifynder/downloads.svg)](https://packagist.org/packages/fenos/notifynder) [![License](https://poser.pugx.org/fenos/Notifynder/license.png)](https://packagist.org/packages/fenos/Notifynder) From f64a21ca2f64fa87323c9faa40a0f556bc1a283b Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Tue, 29 Dec 2015 18:19:38 +0000 Subject: [PATCH 011/210] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ef3d30..65b3ba5 100755 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ php artisan notifynder:create:category "user.following" "{from.username} started To send a notification with notifynder, that's all you have to do. -~~~ +~~~php Notifynder::category('user.following') ->from($from_user_id) ->to($to_user_id) @@ -80,15 +80,15 @@ Notifynder::category('user.following') **Retrieving Notifications** -~~~ +~~~php // @return Collection Notifynder::getAll($user_id,$limit,$paginateBool); ~~~ **Reading Notifications:** -~~~ +~~~php // @return number of notifications read -Notifynder::ReadAll($user_id); +Notifynder::readAll($user_id); ~~~ To know more, such as the advance usage of Notifynder Visit the **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)**. From 0276e480d03e7aec8ac6c96dd878341078001397 Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Fri, 15 Jan 2016 14:17:31 -0600 Subject: [PATCH 012/210] Use Length Aware Paginator Update composer.json Add missing dependency class for paginator Replace simple pagination with length aware pagination change composer info back to the original --- composer.json | 2 +- .../Notifications/NotificationManager.php | 10 +++++----- .../Notifications/NotificationRepository.php | 14 ++------------ 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 6f09e3a..a22999b 100755 --- a/composer.json +++ b/composer.json @@ -38,4 +38,4 @@ } }, "minimum-stability": "stable" -} +} \ No newline at end of file diff --git a/src/Notifynder/Notifications/NotificationManager.php b/src/Notifynder/Notifications/NotificationManager.php index 53a4a36..4bc9ab0 100755 --- a/src/Notifynder/Notifications/NotificationManager.php +++ b/src/Notifynder/Notifications/NotificationManager.php @@ -5,7 +5,7 @@ use Fenos\Notifynder\Contracts\NotifynderNotification; use Fenos\Notifynder\Exceptions\NotificationNotFoundException; use Fenos\Notifynder\Models\Notification as NotificationModel; -use Illuminate\Pagination\Paginator; +use Illuminate\Pagination\LengthAwarePaginator; /** * Class NotifynderNotification @@ -181,8 +181,8 @@ public function getNotRead($to_id, $limit = null, $paginate = null, $orderDate = if(is_int(intval($paginate)) && $paginate) { - return (new Paginator($notifications->parse(), $limit, $paginate, [ - 'path' => Paginator::resolveCurrentPath(), + return (new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ + 'path' => LengthAwarePaginator::resolveCurrentPath() ])); } @@ -209,8 +209,8 @@ public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'de if(is_int(intval($paginate)) && $paginate) { - return (new Paginator($notifications->parse(), $limit, $paginate, [ - 'path' => Paginator::resolveCurrentPath(), + return (new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ + 'path' => LengthAwarePaginator::resolveCurrentPath() ])); } diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index 5e31804..c061395 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -240,12 +240,8 @@ public function getNotRead( $query = $this->applyFilter($filterScope, $query); - if ( is_int($limit)) { - $query->limit($limit); - } - if (is_int(intval($paginate)) && $paginate) { - $query->skip(($paginate - 1) * $limit)->take($limit + 1); + return $query->paginate($limit); } return $query->get(); @@ -280,14 +276,8 @@ public function getAll( $query = $this->applyFilter($filterScope, $query); - - // if the limit is set - if ( is_int($limit)) { - $query->limit($limit); - } - if (is_int(intval($paginate)) && $paginate) { - $query->skip(($paginate - 1) * $limit)->take($limit + 1); + return $query->paginate($limit); } return $query->get(); From 55ab0b9ecacbc791c07727c48c18160a1a9f6571 Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Mon, 18 Jan 2016 16:44:24 -0600 Subject: [PATCH 013/210] revert composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a22999b..6f09e3a 100755 --- a/composer.json +++ b/composer.json @@ -38,4 +38,4 @@ } }, "minimum-stability": "stable" -} \ No newline at end of file +} From ab3f5659c3633692b3b28e135283302b6c56a10d Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Wed, 24 Feb 2016 10:27:07 +0000 Subject: [PATCH 014/210] Fixed Artisan command push:category #80 --- src/Notifynder/Artisan/PushCategoryToGroup.php | 7 +++++-- src/Notifynder/Groups/GroupManager.php | 8 +++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Notifynder/Artisan/PushCategoryToGroup.php b/src/Notifynder/Artisan/PushCategoryToGroup.php index 1d94802..69bc035 100755 --- a/src/Notifynder/Artisan/PushCategoryToGroup.php +++ b/src/Notifynder/Artisan/PushCategoryToGroup.php @@ -41,7 +41,7 @@ class PushCategoryToGroup extends Command * @return \Fenos\Notifynder\Artisan\PushCategoryToGroup */ public function __construct(NotifynderGroup $notifynderGroup, - ArtisanOptionsParser $artisanOptionsParser) + ArtisanOptionsParser $artisanOptionsParser) { parent::__construct(); $this->notifynderGroup = $notifynderGroup; @@ -57,8 +57,11 @@ public function fire() { $arguments = $this->getArgumentsConsole(); + $categoryGroup = array_shift($arguments); + $categories = explode(',',$arguments); + $groupCategories = $this->notifynderGroup - ->addMultipleCategoriesToGroup($arguments); + ->addMultipleCategoriesToGroup($categoryGroup,$categories); if ($groupCategories) { foreach ($groupCategories->categories as $category) { diff --git a/src/Notifynder/Groups/GroupManager.php b/src/Notifynder/Groups/GroupManager.php index 5acaccc..511aee6 100755 --- a/src/Notifynder/Groups/GroupManager.php +++ b/src/Notifynder/Groups/GroupManager.php @@ -108,14 +108,12 @@ public function addCategoryToGroupByName($gorup_name, $category_name) */ public function addMultipleCategoriesToGroup() { - $names = func_get_args(); - - $names = (is_array($names[0])) ? $names[0] : $names; + $args = func_get_args(); // First parameter is the group name - $group_name = array_shift($names); + $group_name = array_shift($args); - $names = (is_array($names[1])) ? $names[1] : $names; + $names = (is_array($args[0])) ? $args[0] : $args; return $this->groupCategory->addMultipleCategoriesToGroup($group_name, $names); } From 697c1d4562683d6dee02dad819e7e17b31950cc5 Mon Sep 17 00:00:00 2001 From: Fabrizio Fenoglio Date: Mon, 14 Mar 2016 23:36:39 +0000 Subject: [PATCH 015/210] Fixed arguments on artisan command #80 --- src/Notifynder/Artisan/PushCategoryToGroup.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Notifynder/Artisan/PushCategoryToGroup.php b/src/Notifynder/Artisan/PushCategoryToGroup.php index 69bc035..5cb1ce1 100755 --- a/src/Notifynder/Artisan/PushCategoryToGroup.php +++ b/src/Notifynder/Artisan/PushCategoryToGroup.php @@ -58,6 +58,7 @@ public function fire() $arguments = $this->getArgumentsConsole(); $categoryGroup = array_shift($arguments); + $arguments = $arguments[0]; $categories = explode(',',$arguments); $groupCategories = $this->notifynderGroup From a37fe5d568b3ae9a77c5e9ec5ca2ce44273e10b5 Mon Sep 17 00:00:00 2001 From: Fabrizio Fenoglio Date: Tue, 15 Mar 2016 09:42:53 +0000 Subject: [PATCH 016/210] fixed limit argument caused merged PR --- src/Notifynder/Notifications/NotificationRepository.php | 8 ++++++++ tests/integration/Notifications/NotificationTest.php | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index c061395..eeeeafa 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -238,6 +238,10 @@ public function getNotRead( ->orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); + if ($limit && !$paginate) { + $query->limit($limit); + } + $query = $this->applyFilter($filterScope, $query); if (is_int(intval($paginate)) && $paginate) { @@ -274,6 +278,10 @@ public function getAll( ->orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); + if ($limit && !$paginate) { + $query->limit($limit); + } + $query = $this->applyFilter($filterScope, $query); if (is_int(intval($paginate)) && $paginate) { diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index ed96d9c..9abbaa4 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -58,9 +58,10 @@ function it_retrieve_notification_by_limiting_the_number() app('config')->set('notifynder.polymorphic',true); $notification = $this->createNotification(['extra' => 'Amazing']); + $this->createMultipleNotifications(['to_id' => $notification->to_id]); $notifications = $this->notification->entity($this->to['type']) - ->getAll($notification->to->id); + ->getAll($notification->to->id,1); $this->assertCount(1,$notifications); } @@ -74,11 +75,11 @@ function it_retrieve_notification_by_paginating_the_number() $category = $this->createCategory(['text' => 'parse this {extra.look} value']); $notification = $this->createNotification(['extra' => $extraValues,'category_id' => $category->id]); + $this->createMultipleNotifications(['to_id' => $notification->to_id]); - $notifications = $this->notification->getNotRead($notification->to->id,10,true); + $notifications = $this->notification->getNotRead($notification->to->id,5,1); - $bodyParsed = 'parse this Amazing value'; - $this->assertEquals($bodyParsed,$notifications->items()[0]->text); + $this->assertCount(5,$notifications); } /** From ef2e0e5cbecb461995421fe8b3201df65ed79bf9 Mon Sep 17 00:00:00 2001 From: jolamar Date: Fri, 18 Mar 2016 09:28:34 -0400 Subject: [PATCH 017/210] adds instructions to run migration --- README.md | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 65b3ba5..ea5e296 100755 --- a/README.md +++ b/README.md @@ -21,30 +21,27 @@ Documentation: **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)** ### Step 1 ### -Add it on your composer.json +Add it on your `composer.json` -~~~ -"fenos/notifynder": "3.1.*" -~~~ + "fenos/notifynder": "3.1.*" -and run **composer update** +and run + + composer update ### Step 2 ### -Add the following string to **config/app.php** +Add the following string to `config/app.php` **Providers array:** -~~~ -'Fenos\Notifynder\NotifynderServiceProvider' -~~~ + Fenos\Notifynder\NotifynderServiceProvider::class, **Aliases array:** -~~~ -'Notifynder' => 'Fenos\Notifynder\Facades\Notifynder' -~~~ + 'Notifynder'=>Fenos\Notifynder\Facades\Notifynder::class, + ### Step 3 ### @@ -52,20 +49,18 @@ Add the following string to **config/app.php** Publish the migration as well as the configuration of notifynder with the following command: -~~~ -php artisan vendor:publish --provider="Fenos\Notifynder\NotifynderServiceProvider" -~~~ + php artisan vendor:publish --provider="Fenos\Notifynder\NotifynderServiceProvider" -Don't forget to migrate. +Run the migration + + php artisan migrate ### Quick Usage ### Set up category of notification, think about it as the body of the notification: -~~~ -php artisan notifynder:create:category "user.following" "{from.username} started to follow you" -~~~ + php artisan notifynder:create:category "user.following" "{from.username} started to follow you" To send a notification with notifynder, that's all you have to do. From ea21d84bf7f26834dda5d605b0ecb3dcf9cc9214 Mon Sep 17 00:00:00 2001 From: Fabrizio Fenoglio Date: Sat, 26 Mar 2016 12:35:28 +0000 Subject: [PATCH 018/210] Fix the state of notifications when using Notifynder Instance within a combination of senders methods --- src/Notifynder/Builder/NotifynderBuilder.php | 14 ++++++-- src/Notifynder/NotifynderManager.php | 34 ++++++++++++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index 164fd5a..b950954 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -231,6 +231,16 @@ public function toArray() throw new NotificationBuilderException($error); } + /** + * Refresh the state of the notifications + */ + public function refresh() + { + $this->notifications = []; + + return $this; + } + /** * @param $var * @return bool @@ -345,7 +355,6 @@ public function offsetSet($offset, $value) } } - /** * @param mixed $offset * @return null @@ -353,4 +362,5 @@ public function offsetSet($offset, $value) public function offsetUnset($offset) { unset($this->notifications[$offset]); -}} + } +} diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index e49e1f5..1c4424b 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -187,7 +187,11 @@ public function send($info = []) { $info = (count($info) > 0) ? $info : $this->toArray(); - return $this->notifynderSender->send($info, $this->defaultCategory); + $notificationSent = $this->notifynderSender->send($info, $this->defaultCategory); + + $this->refresh(); + + return $notificationSent; } /** @@ -201,7 +205,11 @@ public function sendNow($info = []) { $info = (count($info) > 0) ? $info : $this->toArray(); - return $this->notifynderSender->sendNow($info, $this->defaultCategory); + $notificationsSent = $this->notifynderSender->sendNow($info, $this->defaultCategory); + + $this->refresh(); + + return $notificationsSent; } /** @@ -214,7 +222,11 @@ public function sendOne($info = []) { $info = (count($info) > 0) ? $info : $this->toArray(); - return $this->notifynderSender->sendOne($info, $this->defaultCategory); + $notificationSent = $this->notifynderSender->sendOne($info, $this->defaultCategory); + + $this->refresh(); + + return $notificationSent; } /** @@ -227,7 +239,11 @@ public function sendMultiple($info = []) { $info = (count($info) > 0) ? $info : $this->toArray(); - return $this->notifynderSender->sendMultiple($info, $this->defaultCategory); + $notificationsSent = $this->notifynderSender->sendMultiple($info, $this->defaultCategory); + + $this->refresh(); + + return $notificationsSent; } /** @@ -241,7 +257,11 @@ public function sendGroup($group_name, $info = []) { $info = (count($info) > 0) ? $info : $this->toArray(); - return $this->notifynderSender->sendGroup($this, $group_name, $info); + $notificationsSent = $this->notifynderSender->sendGroup($this, $group_name, $info); + + $this->refresh(); + + return $notificationsSent; } /** @@ -598,7 +618,9 @@ public function __call($name, $arguments) $arguments = (isset($arguments[0])) ? $arguments[0] : $this->toArray(); - return $this->notifynderSender->customSender($name,$arguments); + $notificationsSent = $this->notifynderSender->customSender($name,$arguments); + $this->refresh(); + return $notificationsSent; } $error = "method [$name] not found in the class ".self::class; From 9cad1a9813e1f5db0bd81531b40571470426dd8d Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 18 Apr 2016 10:26:47 +0200 Subject: [PATCH 019/210] Update composer.json Fix for issue #97 - the old laravel 5.0 version in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6f09e3a..5717b3a 100755 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "illuminate/support": "5.*" }, "require-dev": { - "laravel/framework": "5.0.*", + "laravel/framework": "~5.1", "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1", "laracasts/testdummy": "~2.0", From 29731d8cab2e0a21e6b38581cfc60f4a1a5bb37e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 18 Apr 2016 10:29:32 +0200 Subject: [PATCH 020/210] Update composer.json fix orchestra/testbench version for new laravel --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5717b3a..4d530d4 100755 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1", "laracasts/testdummy": "~2.0", - "orchestra/testbench": "3.0.*" + "orchestra/testbench": "~3.1" }, "autoload": { "classmap": [ From c9fc266f98345f6e13cf85c98a34d34d25a62a22 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 13:37:38 +0200 Subject: [PATCH 021/210] Update composer.json like discussed in #97 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 4d530d4..6719e9d 100755 --- a/composer.json +++ b/composer.json @@ -12,14 +12,14 @@ ], "require": { "php": ">=5.5.0", - "illuminate/support": "5.*" + "illuminate/support": "~5.0" }, "require-dev": { - "laravel/framework": "~5.1", + "laravel/framework": "~5.0", "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1", "laracasts/testdummy": "~2.0", - "orchestra/testbench": "~3.1" + "orchestra/testbench": "~3.0" }, "autoload": { "classmap": [ From 07261b3a96d9640c423aac0938dbb9ff007add00 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 13:47:19 +0200 Subject: [PATCH 022/210] Use also PHP7 for Travis CI builds Also build and test with php7 as the new php version and official supported evrsion of forge and laravel. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb79058..b2aa3dc 100755 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 5.5 - 5.6 + - 7.0 - hhvm before_script: @@ -12,4 +13,4 @@ before_script: script: - vendor/bin/phpspec run - - vendor/bin/phpunit \ No newline at end of file + - vendor/bin/phpunit From 9ac09e880a5caaa54ac602bc1eb706212ed431ea Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 14:01:01 +0200 Subject: [PATCH 023/210] Update .travis.yml https://docs.travis-ci.com/user/languages/php#Testing-Against-Multiple-Versions-of-Dependencies-(e.g.-Symfony) https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle --- .travis.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb79058..abf7866 100755 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,20 @@ php: - 5.5 - 5.6 - hhvm + +env: + - LARAVEL_VERSION="5.0.*" + - LARAVEL_VERSION="5.1.*" + - LARAVEL_VERSION="5.2.*" -before_script: +install: - composer self-update + - composer require laravel/framework:${LARAVEL_VERSION} - composer install --prefer-source --no-interaction + +before_script: - composer dump-autoload -o script: - vendor/bin/phpspec run - - vendor/bin/phpunit \ No newline at end of file + - vendor/bin/phpunit From 2f54472493bbe18ad912394cf1c12769ddf3f0a5 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 14:16:22 +0200 Subject: [PATCH 024/210] Update .travis.yml prevent composer update on require --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index abf7866..209edcc 100755 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: install: - composer self-update - - composer require laravel/framework:${LARAVEL_VERSION} + - composer require laravel/framework:${LARAVEL_VERSION} --no-update --no-interaction - composer install --prefer-source --no-interaction before_script: From dca198ffe2a55ffc87a2e803248492f072f184d6 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 15:08:45 +0200 Subject: [PATCH 025/210] Prevent publishing migrations that already exist Check if the migration class exists, if not publish the migration if it does ignore this migration. **Reason:** Allow developers to rename the migration files (the date) to bring them in the right order with there own migrations. --- src/Notifynder/NotifynderServiceProvider.php | 48 +++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 0192af4..f627c4f 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -61,6 +61,7 @@ public function register() public function boot() { $this->config(); + $this->migration(); } /** @@ -249,7 +250,6 @@ protected function config() { $this->publishes([ __DIR__.'/../config/notifynder.php' => config_path('notifynder.php'), - __DIR__.'/../migrations/' => base_path('/database/migrations'), ]); // Set use strict_extra config option, @@ -258,6 +258,52 @@ protected function config() NotifynderParser::setStrictExtra($strictParam); } + /** + * Publish migration files + */ + protected function migration() + { + if (!class_exists('NotificationCategories')) { + $this->publishMigration('2014_02_10_145728_notification_categories'); + } + if (!class_exists('CreateNotificationCategories')) { + $this->publishMigration('2014_08_01_210813_create_notification_groups_table'); + } + if (!class_exists('CreateNotificationCategoryNotificationGroupTable')) { + $this->publishMigration('2014_08_01_211045_create_notification_category_notification_group_table'); + } + if (!class_exists('CreateNotificationsTable')) { + $this->publishMigration('2015_05_05_212549_create_notifications_table'); + } + if (!class_exists('AddExpireTimeColumnToNotificationTable')) { + $this->publishMigration('2015_06_06_211555_add_expire_time_column_to_notification_table'); + } + if (!class_exists('ChangeTypeToExtraInNotificationsTable')) { + $this->publishMigration('2015_06_06_211555_change_type_to_extra_in_notifications_table'); + } + if (!class_exists('AlterCategoryNameToUnique')) { + $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique'); + } + } + + protected function publishMigration($filename) + { + $extension = '.php'; + $filename = trim($filename, $extension).$extension; + $stub = __DIR__.'/../migrations/'.$filename; + $target = $this->migrationFilepath($filename); + $this->publishes([$stub => $target], 'migrations'); + } + + protected function migrationFilepath($filename) + { + if(function_exists('database_path')) { + return database_path('/migrations/'.$filename); + } else { + return base_path('/database/migrations/'.$filename); + } + } + /** * Register Artisan commands */ From d3b4df5e643f8bb5992b156649e8000e013abe98 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 15:24:51 +0200 Subject: [PATCH 026/210] add doc tags --- src/Notifynder/NotifynderServiceProvider.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index f627c4f..c0c6597 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -286,6 +286,9 @@ protected function migration() } } + /** + * @param string $filename + */ protected function publishMigration($filename) { $extension = '.php'; @@ -295,6 +298,10 @@ protected function publishMigration($filename) $this->publishes([$stub => $target], 'migrations'); } + /** + * @param string $filename + * @return string + */ protected function migrationFilepath($filename) { if(function_exists('database_path')) { From 68c8443c43bbfd2c727755163b4dd37aaa4a0bb3 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 15:51:15 +0200 Subject: [PATCH 027/210] add code coverage to phpunit --- phpunit.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpunit.xml b/phpunit.xml index dc51e81..a49ef22 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -14,6 +14,14 @@ ./tests/integration + + + ./src + + + + + From 4e00871554e636dd787bd7f2f193af60e8a20309 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 15:52:27 +0200 Subject: [PATCH 028/210] execute the CoverageChecker --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb79058..4627d5f 100755 --- a/.travis.yml +++ b/.travis.yml @@ -12,4 +12,5 @@ before_script: script: - vendor/bin/phpspec run - - vendor/bin/phpunit \ No newline at end of file + - vendor/bin/phpunit + - php CoverageChecker.php clover.xml 50 From 9741f1859155e43a6fd4146e7ddd651c55b1386a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 15:53:10 +0200 Subject: [PATCH 029/210] Create CoverageChecker.php --- CoverageChecker.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 CoverageChecker.php diff --git a/CoverageChecker.php b/CoverageChecker.php new file mode 100644 index 0000000..bd23b1b --- /dev/null +++ b/CoverageChecker.php @@ -0,0 +1,32 @@ +xpath('//metrics'); +$totalElements = 0; +$checkedElements = 0; + +foreach ($metrics as $metric) { + $totalElements += (int)$metric['elements']; + $checkedElements += (int)$metric['coveredelements']; +} + +$coverage = ($checkedElements / $totalElements) * 100; + +echo file_get_contents($inputFile); + +if ($coverage < $percentage) { + echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL; + exit(1); +} + +echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL; From 98cbbdd9f81a08a74d791f933befb17252d0d5de Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 16:14:03 +0200 Subject: [PATCH 030/210] Update CoverageChecker.php --- CoverageChecker.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CoverageChecker.php b/CoverageChecker.php index bd23b1b..ea77107 100644 --- a/CoverageChecker.php +++ b/CoverageChecker.php @@ -3,11 +3,13 @@ $percentage = min(100, max(0, (int)$argv[2])); if (!file_exists($inputFile)) { - throw new InvalidArgumentException('Invalid input file provided'); + echo $inputFile . " isn't present."; + exit(0); } if (!$percentage) { - throw new InvalidArgumentException('An integer checked percentage must be given as second parameter'); + echo $percentage . " isn't percentage."; + exit(0); } $xml = new SimpleXMLElement(file_get_contents($inputFile)); @@ -22,8 +24,6 @@ $coverage = ($checkedElements / $totalElements) * 100; -echo file_get_contents($inputFile); - if ($coverage < $percentage) { echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL; exit(1); From 86d0cdc7afb81595caa1b8e787868f45026e27c0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 16:14:25 +0200 Subject: [PATCH 031/210] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4627d5f..5a6e6ec 100755 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ before_script: script: - vendor/bin/phpspec run - vendor/bin/phpunit - - php CoverageChecker.php clover.xml 50 + - php CoverageChecker.php clover.xml 65 From 70ff4a1cedca5f7515b9c84dd6023ebe0fdde178 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 20:10:20 +0200 Subject: [PATCH 032/210] #84 make url nullable and don't require it --- src/Notifynder/Builder/BuilderRules.php | 2 +- src/Notifynder/Builder/NotifynderBuilder.php | 2 +- ...6_04_19_200827_make_url_nullable_table.php | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/migrations/2016_04_19_200827_make_url_nullable_table.php diff --git a/src/Notifynder/Builder/BuilderRules.php b/src/Notifynder/Builder/BuilderRules.php index 1a01b03..33e47e1 100755 --- a/src/Notifynder/Builder/BuilderRules.php +++ b/src/Notifynder/Builder/BuilderRules.php @@ -18,7 +18,7 @@ trait BuilderRules /** * @var array */ - private $requiredFields = ['from_id','to_id','url','category_id']; + private $requiredFields = ['from_id','to_id','category_id']; /** * Value has to be a string diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index b950954..1f0e0f4 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -227,7 +227,7 @@ public function toArray() } } - $error = "The fields: 'from_id' , 'to_id', 'url', 'category_id' are required"; + $error = "The fields: ".implode(',', $this->requiredFields)." are required"; throw new NotificationBuilderException($error); } diff --git a/src/migrations/2016_04_19_200827_make_url_nullable_table.php b/src/migrations/2016_04_19_200827_make_url_nullable_table.php new file mode 100644 index 0000000..c95ec3b --- /dev/null +++ b/src/migrations/2016_04_19_200827_make_url_nullable_table.php @@ -0,0 +1,32 @@ +string('url')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('notifications', function (Blueprint $table) { + $table->string('url')->change(); + }); + } +} From 28b7f65553b2f1a932377513b53d16eff76c528d Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 20:19:18 +0200 Subject: [PATCH 033/210] #84 make url nullable and don't require it --- ...llable_table.php => 2016_04_19_200827_make_url_nullable.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/migrations/{2016_04_19_200827_make_url_nullable_table.php => 2016_04_19_200827_make_url_nullable.php} (92%) diff --git a/src/migrations/2016_04_19_200827_make_url_nullable_table.php b/src/migrations/2016_04_19_200827_make_url_nullable.php similarity index 92% rename from src/migrations/2016_04_19_200827_make_url_nullable_table.php rename to src/migrations/2016_04_19_200827_make_url_nullable.php index c95ec3b..642c01f 100644 --- a/src/migrations/2016_04_19_200827_make_url_nullable_table.php +++ b/src/migrations/2016_04_19_200827_make_url_nullable.php @@ -3,7 +3,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateNotificationsTable extends Migration +class MakeUrlNullable extends Migration { /** From 0dc8397879cdb3263d45d9e360ec4c570c0b35aa Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 21:02:10 +0200 Subject: [PATCH 034/210] fix missing class for db change --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6719e9d..13fd780 100755 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1", "laracasts/testdummy": "~2.0", - "orchestra/testbench": "~3.0" + "orchestra/testbench": "~3.0", + "doctrine/dbal": "^2.5" }, "autoload": { "classmap": [ From 5d4395ec159ea5a54c1f363f5ed06cde55e18a2d Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 21:41:11 +0200 Subject: [PATCH 035/210] #105 add config for additional fields and allow to add them to be required --- src/Notifynder/Builder/BuilderRules.php | 14 ++++++++++++-- src/Notifynder/Models/Notification.php | 9 +++++++++ src/Notifynder/NotifynderServiceProvider.php | 2 ++ src/config/notifynder.php | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Notifynder/Builder/BuilderRules.php b/src/Notifynder/Builder/BuilderRules.php index 1a01b03..77070eb 100755 --- a/src/Notifynder/Builder/BuilderRules.php +++ b/src/Notifynder/Builder/BuilderRules.php @@ -63,6 +63,16 @@ protected function isNumeric($value) return true; } + /** + * Returns all required fields including the config ones + * + * @return array + */ + public function getRequiredFields() + { + return array_unique($this->requiredFields + config('notifynder.additional_fields.required')); + } + /** * Check that the builder has * the required field to send the @@ -73,7 +83,7 @@ protected function isNumeric($value) */ public function hasRequiredFields($array) { - foreach ($this->requiredFields as $field) { + foreach ($this->getRequiredFields() as $field) { if (! array_key_exists($field, $array)) { return false; } @@ -90,7 +100,7 @@ public function hasRequiredFields($array) */ public function isRequiredField($offset) { - return (in_array($offset,$this->requiredFields)); + return (in_array($offset,$this->getRequiredFields())); } /** diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 2514533..a96915c 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -4,6 +4,7 @@ use Fenos\Notifynder\Parsers\NotifynderParser; use Illuminate\Database\Eloquent\Model; use Carbon\Carbon; +use Illuminate\Support\Arr; /** * Class Notification @@ -36,6 +37,14 @@ class Notification extends Model 'category_id','read','url','extra', 'expire_time', ]; + public function __construct(array $attributes) + { + $fillables = array_unique($this->getFillable() + Arr::flatten(config('notifynder.additional_fields'))); + $this->fillable($fillables); + + parent::__construct($attributes); + } + /** * Custom Collection * diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 0192af4..74c9f63 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -252,6 +252,8 @@ protected function config() __DIR__.'/../migrations/' => base_path('/database/migrations'), ]); + $this->mergeConfigFrom(__DIR__.'/../config/notifynder.php', 'notifynder'); + // Set use strict_extra config option, // you can toggle it in the configuraiton file $strictParam = $this->app['config']->get('notifynder.strict_extra',false); diff --git a/src/config/notifynder.php b/src/config/notifynder.php index eca6c64..3d14117 100755 --- a/src/config/notifynder.php +++ b/src/config/notifynder.php @@ -50,4 +50,21 @@ 'translations' => [ ], + + /** + * If you have added your own fields to the Notification Model + * you can add them to the arrays below. + * + * If you want them to be required by the builder add them to the + * to the required key - if they are just added you can add them + * to the fillable key. + */ + 'additional_fields' => [ + 'required' => [ + + ], + 'fillable' => [ + + ], + ], ]; From 1d01c5025080fd8ece62b8d1cf14534501468c0b Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 21:54:27 +0200 Subject: [PATCH 036/210] fix construct --- src/Notifynder/Models/Notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index a96915c..4d51a8a 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -37,7 +37,7 @@ class Notification extends Model 'category_id','read','url','extra', 'expire_time', ]; - public function __construct(array $attributes) + public function __construct(array $attributes = []) { $fillables = array_unique($this->getFillable() + Arr::flatten(config('notifynder.additional_fields'))); $this->fillable($fillables); From c61f6809378e07555895e0c798a37a1dce2906c6 Mon Sep 17 00:00:00 2001 From: Fabrizio Fenoglio Date: Tue, 19 Apr 2016 22:13:12 +0100 Subject: [PATCH 037/210] phpspec doesnt load laravel so helper function are not allowed in the test case, i now use setterInjection trough IOC --- .../Notifications/NotificationManagerSpec.php | 1 + src/Notifynder/Builder/BuilderRules.php | 9 ++++- src/Notifynder/Builder/NotifynderBuilder.php | 14 +++++++ src/Notifynder/Models/Notification.php | 38 ++++++++++++++++++- src/Notifynder/NotifynderServiceProvider.php | 10 +++++ 5 files changed, 70 insertions(+), 2 deletions(-) diff --git a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php b/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php index 6cca115..8da619c 100755 --- a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php +++ b/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php @@ -6,6 +6,7 @@ use Fenos\Notifynder\Exceptions\NotificationNotFoundException; use Fenos\Notifynder\Models\Notification; use Fenos\Notifynder\Models\NotifynderCollection; +use Illuminate\Contracts\Config\Repository; use Illuminate\Database\Eloquent\Collection; use PhpSpec\ObjectBehavior; use Prophecy\Argument; diff --git a/src/Notifynder/Builder/BuilderRules.php b/src/Notifynder/Builder/BuilderRules.php index 77070eb..bef7d7f 100755 --- a/src/Notifynder/Builder/BuilderRules.php +++ b/src/Notifynder/Builder/BuilderRules.php @@ -1,5 +1,6 @@ requiredFields + config('notifynder.additional_fields.required')); + if (property_exists($this,'config') && $this->config instanceof Repository) { + $customRequiredFields = $this->config->get('notifynder.additional_fields.required'); + } else { + $customRequiredFields = []; + } + + return array_unique($this->requiredFields + $customRequiredFields); } /** diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index b950954..150ac45 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Fenos\Notifynder\Contracts\NotifynderCategory; use Fenos\Notifynder\Exceptions\NotificationBuilderException; +use Illuminate\Contracts\Config\Repository; use InvalidArgumentException; use Traversable; use Closure; @@ -34,6 +35,11 @@ class NotifynderBuilder implements ArrayAccess */ protected $notifications = []; + /** + * @var Repository + */ + protected $config; + /** * @var NotifynderCategory */ @@ -355,6 +361,14 @@ public function offsetSet($offset, $value) } } + /** + * @param Repository $config + */ + public function setConfig(Repository $config) + { + $this->config = $config; + } + /** * @param mixed $offset * @return null diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 4d51a8a..bcc8f86 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -2,6 +2,7 @@ use Fenos\Notifynder\Notifications\ExtraParams; use Fenos\Notifynder\Parsers\NotifynderParser; +use Illuminate\Contracts\Config\Repository; use Illuminate\Database\Eloquent\Model; use Carbon\Carbon; use Illuminate\Support\Arr; @@ -37,9 +38,19 @@ class Notification extends Model 'category_id','read','url','extra', 'expire_time', ]; + /** + * @var Repository + */ + protected $config; + + /** + * Notification constructor. + * + * @param array $attributes + */ public function __construct(array $attributes = []) { - $fillables = array_unique($this->getFillable() + Arr::flatten(config('notifynder.additional_fields'))); + $fillables = array_unique($this->getFillable() + Arr::flatten($this->getFillableFields())); $this->fillable($fillables); parent::__construct($attributes); @@ -173,4 +184,29 @@ public function scopeByCategory($query,$category) $categoryQuery->where('name',$category); }); } + + /** + * Set configuration object + * + * @param Repository $config + */ + public function setConfig(Repository $config) + { + $this->config = $config; + } + + /** + * Get custom required fields from the configs + * so that we can automatically bind them to the model + * fillable property + * + * @return mixed + */ + protected function getFillableFields() + { + if (property_exists($this,'config') && $this->config instanceof Repository) { + return $this->config->get('notifynder.additional_fields'); + } + return []; + } } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 74c9f63..9e35f0d 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -22,6 +22,7 @@ use Fenos\Notifynder\Groups\GroupCategoryRepository; use Fenos\Notifynder\Groups\GroupRepository; use Fenos\Notifynder\Handler\Dispatcher; +use Fenos\Notifynder\Models\Notification; use Fenos\Notifynder\Models\NotificationCategory; use Fenos\Notifynder\Models\NotificationGroup; use Fenos\Notifynder\Notifications\NotificationManager; @@ -122,6 +123,11 @@ protected function notifications() ); }); + // Inject configs when model is resolved + $this->app->resolving(Notification::class, function (Notification $object, $app) { + $object->setConfig($app['config']); + }); + // Default store notification $this->app->bind('notifynder.store', 'notifynder.notification.repository'); } @@ -214,6 +220,10 @@ protected function builder() $app['notifynder.category'] ); }); + + $this->app->resolving(NotifynderBuilder::class, function (NotifynderBuilder $object, $app) { + $object->setConfig($app['config']); + }); } /** From 86b9417c19083c03d0eee9c851ed8248ffcf7c3f Mon Sep 17 00:00:00 2001 From: Fabrizio Fenoglio Date: Tue, 19 Apr 2016 22:44:34 +0100 Subject: [PATCH 038/210] Changed the way i bind custom fillable fields --- src/Notifynder/Models/Notification.php | 23 +++++++++++-------- src/Notifynder/NotifynderServiceProvider.php | 3 ++- .../Notifications/NotificationTest.php | 23 +++++++++++++++++++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index bcc8f86..47b646a 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -38,11 +38,6 @@ class Notification extends Model 'category_id','read','url','extra', 'expire_time', ]; - /** - * @var Repository - */ - protected $config; - /** * Notification constructor. * @@ -50,7 +45,7 @@ class Notification extends Model */ public function __construct(array $attributes = []) { - $fillables = array_unique($this->getFillable() + Arr::flatten($this->getFillableFields())); + $fillables = $this->mergeFillable(); $this->fillable($fillables); parent::__construct($attributes); @@ -202,11 +197,21 @@ public function setConfig(Repository $config) * * @return mixed */ - protected function getFillableFields() + public function getCustomFillableFields() { - if (property_exists($this,'config') && $this->config instanceof Repository) { - return $this->config->get('notifynder.additional_fields'); + if (function_exists('config')) { + return config('notifynder.additional_fields.fillable'); } return []; } + + /** + * @return array + */ + protected function mergeFillable() + { + $fillables = array_unique($this->getFillable() + Arr::flatten($this->getCustomFillableFields())); + + return $fillables; + } } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 9e35f0d..bd3c1cb 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -125,7 +125,8 @@ protected function notifications() // Inject configs when model is resolved $this->app->resolving(Notification::class, function (Notification $object, $app) { - $object->setConfig($app['config']); + $fillable = $app['config']->get('notifynder.additional_fields.fillable'); + $object->fillable(array_merge($object->getFillable(),$fillable)); }); // Default store notification diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 9abbaa4..7ec4b57 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -103,4 +103,27 @@ function it_will_query_for_notification_by_category_name() $this->assertCount(10,$notificationByCategory); } + + /** + * It will check that the fillable fields config option are + * allowing to save the model when resolved trough the ioc + * + * @test + * @group f + */ + function it_will_check_the_fillable_fields_options_are_allowing_to_save_the_model() + { + app('config')->set('notifynder.additional_fields.fillable',[ + 'icon_type' + ]); + + $model = app(\Fenos\Notifynder\Models\Notification::class); + $fillable = [ + 'to_id','to_type','from_id','from_type', + 'category_id','read','url','extra', 'expire_time', + 'icon_type' + ]; + + $this->assertEquals($fillable, $model->getFillable() ); + } } \ No newline at end of file From 2dd70cbacf5b98bc4dabd1e20a2eae5e35c23ab4 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Apr 2016 23:49:22 +0200 Subject: [PATCH 039/210] make the setBuilderData() method public --- src/Notifynder/Builder/NotifynderBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index 150ac45..1a60156 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -319,7 +319,7 @@ protected function getDate() * @param $field * @param $data */ - protected function setBuilderData($field, $data) + public function setBuilderData($field, $data) { return $this->notifications[$field] = $data; } From 8c75748034b2372d9d47e6409656a2919bc45c8c Mon Sep 17 00:00:00 2001 From: Fabrizio Fenoglio Date: Tue, 19 Apr 2016 23:01:00 +0100 Subject: [PATCH 040/210] Added more strictly check on config helper --- src/Notifynder/Models/Notification.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 47b646a..098c7cd 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -3,6 +3,7 @@ use Fenos\Notifynder\Notifications\ExtraParams; use Fenos\Notifynder\Parsers\NotifynderParser; use Illuminate\Contracts\Config\Repository; +use Illuminate\Contracts\Container\Container; use Illuminate\Database\Eloquent\Model; use Carbon\Carbon; use Illuminate\Support\Arr; @@ -180,16 +181,6 @@ public function scopeByCategory($query,$category) }); } - /** - * Set configuration object - * - * @param Repository $config - */ - public function setConfig(Repository $config) - { - $this->config = $config; - } - /** * Get custom required fields from the configs * so that we can automatically bind them to the model @@ -199,8 +190,8 @@ public function setConfig(Repository $config) */ public function getCustomFillableFields() { - if (function_exists('config')) { - return config('notifynder.additional_fields.fillable'); + if (function_exists('app') && app() instanceof Container) { + return Arr::flatten(config('notifynder.additional_fields')); } return []; } @@ -210,7 +201,7 @@ public function getCustomFillableFields() */ protected function mergeFillable() { - $fillables = array_unique($this->getFillable() + Arr::flatten($this->getCustomFillableFields())); + $fillables = array_unique($this->getFillable() + $this->getCustomFillableFields()); return $fillables; } From 55e96762a5f6c6152b41ad03c543be6cf0ec017d Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 20 Apr 2016 10:30:47 +0200 Subject: [PATCH 041/210] try to fix the: Integrity constraint violation: 19 column name is not unique (SQL: insert into "notification_categories" ("name", "text") values (Sister Hane, test notification)) On HHVM and L5.0 --- tests/factories/factories.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/factories/factories.php b/tests/factories/factories.php index acf1bf6..075198c 100755 --- a/tests/factories/factories.php +++ b/tests/factories/factories.php @@ -2,7 +2,7 @@ $factory('Fenos\Notifynder\Models\NotificationCategory',[ - 'name' => $faker->name, + 'name' => uniqid($faker->name, true), 'text' => 'test notification' ]); From 2ff7a27d921232192966bc43e6b109f08120d80c Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 20 Apr 2016 11:05:49 +0200 Subject: [PATCH 042/210] add slack notifications for travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7447cd9..df09c98 100755 --- a/.travis.yml +++ b/.travis.yml @@ -22,3 +22,6 @@ before_script: script: - vendor/bin/phpspec run - vendor/bin/phpunit + +notifications: + slack: notifynder:CnF7P2xaZuJTJ4VzNOy6ksDH \ No newline at end of file From 29df25ece18ec047bcd286212b2a2b8a9a3759cf Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 20 Apr 2016 11:15:21 +0200 Subject: [PATCH 043/210] fix ErrorException: uniqid() expects parameter 1 to be string, object given --- tests/factories/factories.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/factories/factories.php b/tests/factories/factories.php index 075198c..7948c31 100755 --- a/tests/factories/factories.php +++ b/tests/factories/factories.php @@ -2,7 +2,7 @@ $factory('Fenos\Notifynder\Models\NotificationCategory',[ - 'name' => uniqid($faker->name, true), + 'name' => uniqid(), // $faker->name 'text' => 'test notification' ]); From 0f34dca4d54c55f88346036a269bb8ba0e74897a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 20 Apr 2016 11:23:34 +0200 Subject: [PATCH 044/210] uniqueid doesn't help in any way - revert to original --- tests/factories/factories.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/factories/factories.php b/tests/factories/factories.php index 7948c31..acf1bf6 100755 --- a/tests/factories/factories.php +++ b/tests/factories/factories.php @@ -2,7 +2,7 @@ $factory('Fenos\Notifynder\Models\NotificationCategory',[ - 'name' => uniqid(), // $faker->name + 'name' => $faker->name, 'text' => 'test notification' ]); From b858d64889af658a594f612bd7eac1b1e9dc9b39 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 20 Apr 2016 12:11:19 +0200 Subject: [PATCH 045/210] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ea5e296..d1a0daf 100755 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ You get started in a couple of minutes to "enable" notifications in your Laravel Compatible DBs: **MySql** - **PostgresSql** - **Sqlite** Documentation: **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)** + +Community: [Slack](https://notifynder.slack.com) | [Signup](https://notifynder.signup.team) + - - - ## Installation ## From b6f2e7ccb4025cc26aa927f4e0450b7fa9f7b63c Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 20 Apr 2016 12:12:37 +0200 Subject: [PATCH 046/210] Update README.md make links bold --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1a0daf..8014799 100755 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Compatible DBs: **MySql** - **PostgresSql** - **Sqlite** Documentation: **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)** -Community: [Slack](https://notifynder.slack.com) | [Signup](https://notifynder.signup.team) +Community: **[Slack](https://notifynder.slack.com)** | **[Signup](https://notifynder.signup.team)** - - - From 1b5b4d5cb20666fe6f89cc9a5c176ea220c49c4f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 22 Apr 2016 13:18:53 +0200 Subject: [PATCH 047/210] Issue #84 pls use the getRequiredFields() method in the exception message after merging the PR #106 --- src/Notifynder/Builder/NotifynderBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index 5eb8d61..8becb97 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -233,7 +233,7 @@ public function toArray() } } - $error = "The fields: ".implode(',', $this->requiredFields)." are required"; + $error = "The fields: ".implode(',', $this->getRequiredFields())." are required"; throw new NotificationBuilderException($error); } From 9633de26270192d180bc0b064106108335328304 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 22 Apr 2016 14:49:33 +0200 Subject: [PATCH 048/210] Issue #100 cache composer - add github oauth token --- .travis.yml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6d1a402..d701d03 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,43 @@ language: php +## Run on container environment +sudo: false + +## Cache composer bits +cache: + directories: + - $HOME/.composer/cache + +## List all PHP versions to test with php: - 5.5 - 5.6 - 7.0 - hhvm - + +## Define all ENV vars to test with env: - LARAVEL_VERSION="5.0.*" - LARAVEL_VERSION="5.1.*" - LARAVEL_VERSION="5.2.*" +## Install Dependencies install: - composer self-update + - if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi; - composer require laravel/framework:${LARAVEL_VERSION} --no-update --no-interaction - - composer install --prefer-source --no-interaction - + - composer install --prefer-dist --no-interaction + +## Run Scripts before Tests before_script: - composer dump-autoload -o +## Run test Scripts script: - vendor/bin/phpspec run - vendor/bin/phpunit - php CoverageChecker.php clover.xml 65 +## Send Build Notifications to Slack notifications: - slack: notifynder:CnF7P2xaZuJTJ4VzNOy6ksDH + slack: notifynder:CnF7P2xaZuJTJ4VzNOy6ksDH \ No newline at end of file From 3206150e610658b427b68695569d924ed3523654 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 25 Apr 2016 15:09:17 +0200 Subject: [PATCH 049/210] fix migration publishing --- src/Notifynder/NotifynderServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 49441ff..61db464 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -279,7 +279,7 @@ protected function migration() if (!class_exists('NotificationCategories')) { $this->publishMigration('2014_02_10_145728_notification_categories'); } - if (!class_exists('CreateNotificationCategories')) { + if (!class_exists('CreateNotificationGroupsTable')) { $this->publishMigration('2014_08_01_210813_create_notification_groups_table'); } if (!class_exists('CreateNotificationCategoryNotificationGroupTable')) { From f7b138007d2d4e0e4a8cef7e988c240de37921ba Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 26 Apr 2016 18:04:22 +0200 Subject: [PATCH 050/210] Issue #110 --- src/Notifynder/Builder/NotifynderBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index 8becb97..bc4d58d 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -5,6 +5,7 @@ use Fenos\Notifynder\Contracts\NotifynderCategory; use Fenos\Notifynder\Exceptions\NotificationBuilderException; use Illuminate\Contracts\Config\Repository; +use Illuminate\Database\Eloquent\Model; use InvalidArgumentException; use Traversable; use Closure; @@ -275,6 +276,9 @@ protected function setEntityAction($from, $property) $this->setBuilderData("{$property}_type", $from[0]); $this->setBuilderData("{$property}_id", $from[1]); + } elseif($from[0] instanceof Model) { + $this->setBuilderData("{$property}_type", get_class($from[0])); + $this->setBuilderData("{$property}_id", $from[0]->getKey()); } else { $this->isNumeric($from[0]); $this->setBuilderData("{$property}_id", $from[0]); From 158b135f5be76468d89cb5b997c1026e44a5a0ad Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 27 Apr 2016 10:53:02 +0200 Subject: [PATCH 051/210] Issue #110 update `get_class()` to `getMorphClass()` --- src/Notifynder/Builder/NotifynderBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index bc4d58d..6e24961 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -277,7 +277,7 @@ protected function setEntityAction($from, $property) $this->setBuilderData("{$property}_type", $from[0]); $this->setBuilderData("{$property}_id", $from[1]); } elseif($from[0] instanceof Model) { - $this->setBuilderData("{$property}_type", get_class($from[0])); + $this->setBuilderData("{$property}_type", $from[0]->getMorphClass()); $this->setBuilderData("{$property}_id", $from[0]->getKey()); } else { $this->isNumeric($from[0]); From d38de2e5c5cb71b006c784cefccb5fd94e14ac16 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 2 May 2016 10:31:35 +0200 Subject: [PATCH 052/210] Issue #113 try to fix the expect array not null exception --- src/Notifynder/Models/Notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 098c7cd..e82fb4c 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -191,7 +191,7 @@ public function scopeByCategory($query,$category) public function getCustomFillableFields() { if (function_exists('app') && app() instanceof Container) { - return Arr::flatten(config('notifynder.additional_fields')); + return Arr::flatten(config('notifynder.additional_fields', [])); } return []; } From 7c0078128f91df6f76f9008d18520d3574f1f32d Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 2 May 2016 17:44:24 +0200 Subject: [PATCH 053/210] Issue #113 try to fix the expect array not null exception --- src/Notifynder/NotifynderServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 61db464..e966239 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -126,7 +126,7 @@ protected function notifications() // Inject configs when model is resolved $this->app->resolving(Notification::class, function (Notification $object, $app) { - $fillable = $app['config']->get('notifynder.additional_fields.fillable'); + $fillable = $app['config']->get('notifynder.additional_fields.fillable', []); $object->fillable(array_merge($object->getFillable(),$fillable)); }); From 5b789fb3a8f5cbfad0d1c8c61973f70fc64c0d21 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 12:35:15 +0200 Subject: [PATCH 054/210] Issue #9 allow multiple dots to get a value out of the extra and/or relations --- src/Notifynder/Parsers/NotifynderParser.php | 158 ++++++-------------- 1 file changed, 44 insertions(+), 114 deletions(-) diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index eb3010a..b1a8694 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -29,23 +29,28 @@ class NotifynderParser * values * * @param $item - * @return array|mixed + * @return string + * @throws \Fenos\Notifynder\Exceptions\ExtraParamsException */ public function parse($item) { $body = $item['body']['text']; - $extraParam = $item['extra']; - // Decode the data passed into an array - //$extra = json_decode($extra); $specialValues = $this->getValues($body); - if ($specialValues > 0) { - - list($extractedExtra, $relationsToReplace) = $this->categorizeSpecialValues($specialValues); + if (count($specialValues) > 0) { + $specialValues = array_filter($specialValues, function($value) { + return (starts_with($value, 'extra.') || starts_with($value, 'to.') || starts_with($value, 'from.')); + }); - $body = $this->replaceExtraValues($extractedExtra, $extraParam, $body); - $body = $this->replaceValuesRelations($item, $relationsToReplace, $body); + foreach ($specialValues as $replacer) { + $replace = $this->mixedGet($item, $replacer); + if(empty($replace) && static::$strictMode) { + $error = "the following [$replacer] param required from your category it's missing. Did you forget to store it?"; + throw new ExtraParamsException($error); + } + $body = $this->replaceBody($body, $replace, $replacer); + } } return $body; @@ -64,111 +69,6 @@ public static function setStrictExtra($set = true) static::$strictMode = $set; } - /** - * I categorize into 2 arrays - * the relations values - * and extras values - * - * @param $specialValues - * @return array - */ - protected function categorizeSpecialValues($specialValues) - { - $extrasToReplace = []; - $relationsToReplace = []; - - foreach ($specialValues as $specialValue) { - - if (starts_with($specialValue, 'extra.')) { - $extrasToReplace[] = $specialValue; - } else { - if (starts_with($specialValue, 'to.') or - starts_with($specialValue, 'from.') - ) { - $relationsToReplace[] = $specialValue; - } - } - } - - return array($extrasToReplace, $relationsToReplace); - } - - /** - * This method replace extra values - * within the {extra.*} namespace. - * - * - * @param $extrasToReplace - * @param $extra - * @param $body - * @return array - * @throws ExtraParamsException - */ - protected function replaceExtraValues($extrasToReplace, $extra, $body) - { - // I'll try my best to have returned the - // extra param as an array - $extra = $this->extraToArray($extra); - - // wildcard - foreach ($extrasToReplace as $replacer) { - $valueMatch = explode('.', $replacer)[1]; - - // Let's cover the scenario where the developer - // forget to add the extra param to a category that it's - // needed. Ex: caterogy name:"hi" text:"hello {extra.name}" - // developer store the notification without passing the value to extra - // into the db will be NULL. This will just remove the {extra.hello}. - // In production it's better a "typo" mistake in the text then an Exception. - // however we can force to throw an Exception for development porpose - // NotifynderParser::setExtraStrict(true); - if ( !is_array($extra) or (is_array($extra) and count($extra) == 0) ) { - - $body = $this->replaceBody($body, '', $replacer); - - // In strict mode you'll be aware - if (static::$strictMode) { - $error = "the following [$replacer] param required from your category it's missing. Did you forget to store it?"; - throw new ExtraParamsException($error); - } - - break; - } - - if (array_key_exists($valueMatch, $extra)) { - - $body = $this->replaceBody($body, $extra[$valueMatch], $replacer); - } - } - - return $body; - } - - /** - * Replace relations values as - * 'to' and 'from', that means you - * can have parsed value from the current - * relation {to.name} name who received - * notification - * - * @param $item - * @param $relationsToReplace - * @param $body - * @return mixed - */ - protected function replaceValuesRelations($item, $relationsToReplace, $body) - { - foreach ($relationsToReplace as $replacer) { - $valueMatch = explode('.', $replacer); - $relation = $valueMatch[0]; - $field = $valueMatch[1]; - - $body = str_replace('{'.$replacer.'}', $item[$relation][$field], $body); - } - - return $body; - } - /** * Get the values between {} * and return an array of it @@ -237,4 +137,34 @@ protected function isJson($value) return (json_last_error() == JSON_ERROR_NONE); } + + + /** + * Get a value by dot-key of an array, object or mix of both + * + * @param array|object $object + * @param string $key + * @param null $default + * @return mixed + */ + protected function mixedGet($object, $key, $default = null) + { + if (is_null($key) || trim($key) == '') { + return ''; + } + + foreach (explode('.', $key) as $segment) { + if (is_object($object) && isset($object->{$segment})) { + $object = $object->{$segment}; + } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { + $object = $object->getAttribute($segment); + } elseif (is_array($object) && array_key_exists($segment, $object)) { + $object = array_get($object, $segment, $default); + } else { + return value($default); + } + } + + return $object; + } } \ No newline at end of file From 84285396f47a4fbe4e4abdc80429ae0cd66851a3 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 12:50:04 +0200 Subject: [PATCH 055/210] fix extra as json and not array --- src/Notifynder/Parsers/NotifynderParser.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index b1a8694..2876899 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -36,6 +36,7 @@ public function parse($item) { $body = $item['body']['text']; + $item['extra'] = $this->extraToArray($item['extra']); $specialValues = $this->getValues($body); if (count($specialValues) > 0) { From 65e72677162e05b96b70c97dbc70458e0b9fae38 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 13:55:37 +0200 Subject: [PATCH 056/210] fix extra as json and not array --- src/Notifynder/Models/Notification.php | 8 +++++++- src/Notifynder/Parsers/NotifynderParser.php | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index e82fb4c..a0fabd4 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -159,7 +159,13 @@ public function getNotifyBodyAttribute() */ public function getExtraAttribute($value) { - return new ExtraParams(json_decode($value)); + if(is_array($value)) { + return new ExtraParams($value); + } elseif(is_string($value)) { + return new ExtraParams(json_decode($value)); + } else { + return new ExtraParams([]); + } } /** diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index 2876899..0ff4fc0 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -154,6 +154,13 @@ protected function mixedGet($object, $key, $default = null) return ''; } + if(($value = array_get($object, $key, $default)) != $default) { + return $value; + } + if(($value = object_get($object, $key, $default)) != $default) { + return $value; + } + foreach (explode('.', $key) as $segment) { if (is_object($object) && isset($object->{$segment})) { $object = $object->{$segment}; From f33a685cd7befdcc1fb614a74c998f35bc7333c7 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 15:08:38 +0200 Subject: [PATCH 057/210] fix extra as json and not array --- src/Notifynder/Notifications/ExtraParams.php | 4 +++- src/Notifynder/Parsers/NotifynderParser.php | 9 ++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Notifynder/Notifications/ExtraParams.php b/src/Notifynder/Notifications/ExtraParams.php index 1bc5878..febf90f 100644 --- a/src/Notifynder/Notifications/ExtraParams.php +++ b/src/Notifynder/Notifications/ExtraParams.php @@ -92,7 +92,9 @@ function __get($name) { $params = $this->toArray(); - return $params[$name]; + if(array_key_exists($name, $params)) { + return $params[$name]; + } } diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index 0ff4fc0..58ba5ce 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -154,16 +154,11 @@ protected function mixedGet($object, $key, $default = null) return ''; } - if(($value = array_get($object, $key, $default)) != $default) { - return $value; - } - if(($value = object_get($object, $key, $default)) != $default) { - return $value; - } - foreach (explode('.', $key) as $segment) { if (is_object($object) && isset($object->{$segment})) { $object = $object->{$segment}; + } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { + $object = $object->__get($segment); } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { $object = $object->getAttribute($segment); } elseif (is_array($object) && array_key_exists($segment, $object)) { From 041e3f433e6bfd0132b1cb62a276591f4e70b7b1 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 15:30:54 +0200 Subject: [PATCH 058/210] add test for multi dot keys --- .../integration/Notifications/NotificationTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 7ec4b57..5760568 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -126,4 +126,18 @@ function it_will_check_the_fillable_fields_options_are_allowing_to_save_the_mode $this->assertEquals($fillable, $model->getFillable() ); } + + /** @test */ + function it_retrieve_notification_with_parsed_body_and_multi_dots() + { + $extraValues = json_encode(['look' => 'Amazing', 'user' => ['last' => 'Doe', 'first' => 'John'],]); + $category = $this->createCategory(['text' => 'parse this {extra.look} value from {extra.user.first} {extra.user.last}']); + + $notification = $this->createNotification(['extra' => $extraValues,'category_id' => $category->id]); + + $notifications = $this->notification->getNotRead($notification->to->id); + + $bodyParsed = 'parse this Amazing value from John Doe'; + $this->assertEquals($bodyParsed,$notifications[0]->text); + } } \ No newline at end of file From bb3215a8f7a9ef9290a581cca4b4772b70299caf Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 16:01:22 +0200 Subject: [PATCH 059/210] add test with multiple objects and model --- .../Notifications/NotificationTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 5760568..a26f890 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -140,4 +140,24 @@ function it_retrieve_notification_with_parsed_body_and_multi_dots() $bodyParsed = 'parse this Amazing value from John Doe'; $this->assertEquals($bodyParsed,$notifications[0]->text); } + + /** @test */ + function it_retrieve_notification_with_parsed_body_and_multi_dots_with_objects() + { + $user = new \Fenos\Tests\Models\User(['id' => '1']); + $object = json_decode(json_encode(['last' => 'Doe', 'first' => 'John']), false); + + $this->assertInstanceOf(\Fenos\Tests\Models\User::class, $user); + $this->assertInstanceOf(stdClass::class, $object); + + $extraValues = json_encode(['look' => 'Amazing', 'user' => $user, 'object' => $object,]); + $category = $this->createCategory(['text' => 'parse this {extra.look} value from User#{extra.user.id} ({extra.object.first} {extra.object.last})']); + + $notification = $this->createNotification(['extra' => $extraValues,'category_id' => $category->id]); + + $notifications = $this->notification->getNotRead($notification->to->id); + + $bodyParsed = 'parse this Amazing value from User#1 (John Doe)'; + $this->assertEquals($bodyParsed,$notifications[0]->text); + } } \ No newline at end of file From aecd99ef41f05d07d03179d463779763d1f312b1 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 20:09:17 +0200 Subject: [PATCH 060/210] Issue #118 throw exception in the `loop()` method if the iterable is empty. --- src/Notifynder/Builder/NotifynderBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index 6e24961..e4a71fe 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -254,7 +254,7 @@ public function refresh() */ protected function isIterable($var) { - return (is_array($var) || $var instanceof Traversable); + return (is_array($var) || $var instanceof Traversable) && count($var) > 0; } /** From 68e7b701d534984cac06cba0627e9acafdc043ac Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 20:22:43 +0200 Subject: [PATCH 061/210] add phpspec tests for empty array & collection --- .../Builder/NotifynderBuilderSpec.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php b/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php index 3c609ea..08fdf69 100755 --- a/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php +++ b/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php @@ -6,6 +6,7 @@ use Fenos\Notifynder\Builder\NotifynderBuilder; use Fenos\Notifynder\Categories\CategoryManager; use Fenos\Notifynder\Models\NotificationCategory; +use Illuminate\Support\Collection; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -92,6 +93,8 @@ function it_allow_only_string_as_url() /** @test */ function it_add_the_expire_parameter_to_the_builder() { + date_default_timezone_set('UTC'); + $datetime = new Carbon; $this->expire($datetime)->shouldReturnAnInstanceOf(NotifynderBuilder::class); @@ -164,9 +167,27 @@ function it_create_a_builder_array_using_a_raw_closure() public function it_create_multi_notification_in_a_loop() { - $cloure = function(NotifynderBuilder $builder,$data,$key) + $closure = function(NotifynderBuilder $builder,$data,$key) + { + return $builder->to(1)->from(2)->url('notifynder.io')->category(1); + }; + } + + public function it_create_empty_array_loop_builder() + { + $closure = function(NotifynderBuilder $builder,$data,$key) + { + return $builder->to(1)->from(2)->url('notifynder.io')->category(1); + }; + $this->shouldThrow('InvalidArgumentException')->during('loop', [[], $closure]); + } + + public function it_create_empty_collection_loop_builder() + { + $closure = function(NotifynderBuilder $builder,$data,$key) { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; + $this->shouldThrow('InvalidArgumentException')->during('loop', [new Collection([]), $closure]); } } From 8e2bf8e7ed8c160060319d360c9104127c2c07f8 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 3 May 2016 22:01:38 +0200 Subject: [PATCH 062/210] add two exceptions for the empty or not iterable loop data --- .../Builder/NotifynderBuilderSpec.php | 15 +++++++-- src/Notifynder/Builder/NotifynderBuilder.php | 33 +++++++++++-------- .../Exceptions/EntityNotIterableException.php | 12 +++++++ .../Exceptions/IterableIsEmptyException.php | 12 +++++++ 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 src/Notifynder/Exceptions/EntityNotIterableException.php create mode 100644 src/Notifynder/Exceptions/IterableIsEmptyException.php diff --git a/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php b/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php index 08fdf69..ec59a80 100755 --- a/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php +++ b/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php @@ -5,6 +5,8 @@ use Carbon\Carbon; use Fenos\Notifynder\Builder\NotifynderBuilder; use Fenos\Notifynder\Categories\CategoryManager; +use Fenos\Notifynder\Exceptions\EntityNotIterableException; +use Fenos\Notifynder\Exceptions\IterableIsEmptyException; use Fenos\Notifynder\Models\NotificationCategory; use Illuminate\Support\Collection; use PhpSpec\ObjectBehavior; @@ -179,7 +181,7 @@ public function it_create_empty_array_loop_builder() { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; - $this->shouldThrow('InvalidArgumentException')->during('loop', [[], $closure]); + $this->shouldThrow(IterableIsEmptyException::class)->during('loop', [[], $closure]); } public function it_create_empty_collection_loop_builder() @@ -188,6 +190,15 @@ public function it_create_empty_collection_loop_builder() { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; - $this->shouldThrow('InvalidArgumentException')->during('loop', [new Collection([]), $closure]); + $this->shouldThrow(IterableIsEmptyException::class)->during('loop', [new Collection([]), $closure]); + } + + public function it_create_not_iterable_loop_builder() + { + $closure = function(NotifynderBuilder $builder,$data,$key) + { + return $builder->to(1)->from(2)->url('notifynder.io')->category(1); + }; + $this->shouldThrow(EntityNotIterableException::class)->during('loop', ['hello world', $closure]); } } diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index e4a71fe..8ffa213 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -3,10 +3,11 @@ use ArrayAccess; use Carbon\Carbon; use Fenos\Notifynder\Contracts\NotifynderCategory; +use Fenos\Notifynder\Exceptions\EntityNotIterableException; +use Fenos\Notifynder\Exceptions\IterableIsEmptyException; use Fenos\Notifynder\Exceptions\NotificationBuilderException; use Illuminate\Contracts\Config\Repository; use Illuminate\Database\Eloquent\Model; -use InvalidArgumentException; use Traversable; use Closure; @@ -175,26 +176,30 @@ public function raw(Closure $closure) * @param $dataToIterate * @param Closure $builder * @return $this - * @throws NotificationBuilderException + * @throws \Fenos\Notifynder\Exceptions\IterableIsEmptyException + * @throws \Fenos\Notifynder\Exceptions\EntityNotIterableException */ public function loop($dataToIterate, Closure $builder) { if ($this->isIterable($dataToIterate)) { - $notifications = []; + if(count($dataToIterate) > 0) { + $notifications = []; - $newBuilder = new self($this->notifynderCategory); + $newBuilder = new self($this->notifynderCategory); - foreach ($dataToIterate as $key => $data) { - $builder($newBuilder, $data, $key); - $notifications[] = $newBuilder->toArray(); - } + foreach ($dataToIterate as $key => $data) { + $builder($newBuilder, $data, $key); + $notifications[] = $newBuilder->toArray(); + } - $this->notifications = $notifications; - return $this; + $this->notifications = $notifications; + return $this; + } else { + throw new IterableIsEmptyException('The Iterable passed must contain at least one element'); + } + } else { + throw new EntityNotIterableException('The data passed must be itarable'); } - - $error = "The data passed must be itarable"; - throw new InvalidArgumentException($error); } /** @@ -254,7 +259,7 @@ public function refresh() */ protected function isIterable($var) { - return (is_array($var) || $var instanceof Traversable) && count($var) > 0; + return (is_array($var) || $var instanceof Traversable); } /** diff --git a/src/Notifynder/Exceptions/EntityNotIterableException.php b/src/Notifynder/Exceptions/EntityNotIterableException.php new file mode 100644 index 0000000..40a5893 --- /dev/null +++ b/src/Notifynder/Exceptions/EntityNotIterableException.php @@ -0,0 +1,12 @@ + Date: Wed, 4 May 2016 10:41:18 +0200 Subject: [PATCH 063/210] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8014799..747a8d6 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Notifynder 3.1 - Laravel 5 +Notifynder 3.2 - Laravel 5 ========== [![Build Status](https://travis-ci.org/fenos/Notifynder.svg?branch=master)](https://travis-ci.org/fenos/Notifynder) From 606f25f27b439bf625a0e5f378a41e882b3fb031 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 4 May 2016 13:45:15 +0200 Subject: [PATCH 064/210] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..405477b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Fabrizio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 3d65480238e2a160020aee113c4ec67bf32f3f8a Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Tue, 17 May 2016 11:00:10 +0100 Subject: [PATCH 065/210] Create .styleci.yml --- .styleci.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .styleci.yml diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..7096010 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,5 @@ +preset: laravel + +risky: false + +linting: true From f15caf712261fe586022a887bc74cf893c4b523f Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Tue, 17 May 2016 06:02:41 -0400 Subject: [PATCH 066/210] Applied fixes from StyleCI --- CoverageChecker.php | 19 +-- .../Builder/NotifynderBuilderSpec.php | 63 ++++----- .../Categories/CategoryManagerSpec.php | 19 ++- .../Notifynder/Groups/GroupManagerSpec.php | 41 +++--- .../Notifynder/Handler/DispatcherSpec.php | 21 ++- .../Notifications/NotificationManagerSpec.php | 69 +++++----- .../Parsers/NotifynderParserSpec.php | 45 +++---- .../Notifynder/Senders/SendMultipleSpec.php | 5 +- spec/Fenos/Notifynder/Senders/SendOneSpec.php | 11 +- .../Notifynder/Senders/SenderFactorySpec.php | 19 ++- .../Notifynder/Senders/SenderManagerSpec.php | 34 +++-- .../Translator/TranslatorManagerSpec.php | 36 +++-- src/Notifynder/Artisan/CreateCategory.php | 13 +- src/Notifynder/Artisan/CreateGroup.php | 11 +- src/Notifynder/Artisan/DeleteCategory.php | 11 +- .../Artisan/PushCategoryToGroup.php | 21 +-- src/Notifynder/Builder/BuilderRules.php | 45 ++++--- src/Notifynder/Builder/NotifynderBuilder.php | 63 ++++----- src/Notifynder/Categories/CategoryManager.php | 29 ++-- .../Categories/CategoryRepository.php | 23 ++-- src/Notifynder/Contracts/CategoryDB.php | 23 ++-- src/Notifynder/Contracts/DefaultSender.php | 11 +- src/Notifynder/Contracts/NotificationDB.php | 42 +++--- src/Notifynder/Contracts/NotifyListener.php | 14 +- .../Contracts/NotifynderCategory.php | 23 ++-- .../Contracts/NotifynderDispatcher.php | 21 ++- src/Notifynder/Contracts/NotifynderGroup.php | 21 ++- .../Contracts/NotifynderGroupCategoryDB.php | 15 +-- .../Contracts/NotifynderGroupDB.php | 17 ++- .../Contracts/NotifynderNotification.php | 59 ++++---- src/Notifynder/Contracts/NotifynderSender.php | 25 ++-- .../Contracts/NotifynderTranslator.php | 15 +-- src/Notifynder/Contracts/Sender.php | 16 +-- .../Contracts/StoreNotification.php | 13 +- .../Exceptions/CategoryNotFoundException.php | 8 +- .../Exceptions/EntityNotIterableException.php | 8 +- .../EntityNotSpecifiedException.php | 8 +- .../Exceptions/ExtraParamsException.php | 7 +- .../Exceptions/IterableIsEmptyException.php | 8 +- .../NotificationBuilderException.php | 8 +- .../NotificationLanguageNotFoundException.php | 8 +- .../NotificationNotFoundException.php | 8 +- ...tificationTranslationNotFoundException.php | 8 +- .../NotifynderGroupNotFoundException.php | 8 +- src/Notifynder/Facades/Notifynder.php | 5 +- .../Groups/GroupCategoryRepository.php | 15 +-- src/Notifynder/Groups/GroupManager.php | 29 ++-- src/Notifynder/Groups/GroupRepository.php | 17 ++- src/Notifynder/Handler/Dispatcher.php | 35 +++-- src/Notifynder/Handler/NotifynderEvent.php | 13 +- src/Notifynder/Handler/NotifynderHandler.php | 23 ++-- src/Notifynder/Models/Notification.php | 44 +++--- .../Models/NotificationCategory.php | 17 ++- src/Notifynder/Models/NotificationGroup.php | 11 +- .../Models/NotifynderCollection.php | 16 +-- src/Notifynder/Notifable.php | 43 +++--- src/Notifynder/Notifications/ExtraParams.php | 36 ++--- .../Notifications/NotificationManager.php | 75 +++++------ .../Notifications/NotificationRepository.php | 56 ++++---- src/Notifynder/Notifynder.php | 91 +++++++------ src/Notifynder/NotifynderManager.php | 127 +++++++++--------- src/Notifynder/NotifynderServiceProvider.php | 51 +++---- .../Parsers/ArtisanOptionsParser.php | 11 +- src/Notifynder/Parsers/NotifynderParser.php | 52 ++++--- src/Notifynder/Senders/SendGroup.php | 11 +- src/Notifynder/Senders/SendMultiple.php | 11 +- src/Notifynder/Senders/SendOne.php | 17 ++- src/Notifynder/Senders/SenderFactory.php | 31 ++--- src/Notifynder/Senders/SenderManager.php | 41 +++--- src/Notifynder/Translator/Compiler.php | 15 +-- .../Translator/TranslatorManager.php | 21 ++- src/config/notifynder.php | 12 +- ...4_02_10_145728_notification_categories.php | 1 - ...10813_create_notification_groups_table.php | 1 - ...tion_category_notification_group_table.php | 1 - ...5_05_212549_create_notifications_table.php | 1 - ...pire_time_column_to_notification_table.php | 1 - ...e_type_to_extra_in_notifications_table.php | 15 +-- ...7_211555_alter_category_name_to_unique.php | 1 - .../2016_04_19_200827_make_url_nullable.php | 1 - tests/TestCaseDB.php | 25 ++-- tests/factories/factories.php | 15 +-- tests/integration/CreateModels.php | 26 ++-- tests/integration/CustomSender.php | 11 +- tests/integration/Handler/NotifyEvent.php | 10 +- .../Handler/NotifynderHandlerTest.php | 69 +++++----- tests/integration/Notifable/NotifableTest.php | 62 ++++----- .../Notifications/NotificationTest.php | 81 +++++------ .../Notifications/NotifynderTest.php | 44 +++--- .../GroupCategoryReposutoryTest.php | 23 ++-- .../Repositories/GroupRepositoryTest.php | 25 ++-- .../NotificationCategoryDBTest.php | 43 +++--- .../NotificationRepositoryDBTest.php | 118 ++++++++-------- tests/integration/Senders/SendersTest.php | 36 +++-- .../integration/Translator/TranslatorTest.php | 20 +-- tests/integration/Translator/translations.php | 6 +- .../2014_08_01_164248_create_users_table.php | 39 +++--- tests/models/User.php | 10 +- 98 files changed, 1253 insertions(+), 1350 deletions(-) diff --git a/CoverageChecker.php b/CoverageChecker.php index ea77107..5a4c2c6 100644 --- a/CoverageChecker.php +++ b/CoverageChecker.php @@ -1,14 +1,15 @@ beConstructedWith($category); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Builder\NotifynderBuilder'); } /** @test */ - function it_set_the_FROM_value_with_a_single_entity() + public function it_set_the_FROM_value_with_a_single_entity() { $user_id = 1; @@ -33,25 +32,25 @@ function it_set_the_FROM_value_with_a_single_entity() } /** @test */ - function it_set_the_FROM_value_giving_a_polymorphic_entity() + public function it_set_the_FROM_value_giving_a_polymorphic_entity() { $user_id = 1; $user_class = 'User'; - $this->from($user_class,$user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); + $this->from($user_class, $user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); } /** @test */ - function it_set_the_FROM_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity() + public function it_set_the_FROM_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity() { $user_id = 1; $user_class = 'User'; - $this->shouldThrow('InvalidArgumentException')->during('from',[$user_id,$user_class]); + $this->shouldThrow('InvalidArgumentException')->during('from', [$user_id, $user_class]); } /** @test */ - function it_set_the_TO_value_with_a_single_entity() + public function it_set_the_TO_value_with_a_single_entity() { $user_id = 1; @@ -59,25 +58,25 @@ function it_set_the_TO_value_with_a_single_entity() } /** @test */ - function it_set_the_TO_value_giving_a_polymorphic_entity() + public function it_set_the_TO_value_giving_a_polymorphic_entity() { $user_id = 1; $user_class = 'User'; - $this->to($user_class,$user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); + $this->to($user_class, $user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); } /** @test */ - function it_set_the_TO_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity() + public function it_set_the_TO_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity() { $user_id = 1; $user_class = 'User'; - $this->shouldThrow('InvalidArgumentException')->during('to',[$user_id,$user_class]); + $this->shouldThrow('InvalidArgumentException')->during('to', [$user_id, $user_class]); } /** @test */ - function it_add_the_url_parameter_to_the_builder() + public function it_add_the_url_parameter_to_the_builder() { $url = 'www.notifynder.io'; @@ -85,15 +84,15 @@ function it_add_the_url_parameter_to_the_builder() } /** @test */ - function it_allow_only_string_as_url() + public function it_allow_only_string_as_url() { $url = 1; - $this->shouldThrow('InvalidArgumentException')->during('url',[$url]); + $this->shouldThrow('InvalidArgumentException')->during('url', [$url]); } /** @test */ - function it_add_the_expire_parameter_to_the_builder() + public function it_add_the_expire_parameter_to_the_builder() { date_default_timezone_set('UTC'); @@ -103,16 +102,15 @@ function it_add_the_expire_parameter_to_the_builder() } /** @test */ - function it_allow_only_carbon_instance_as_expire_time() + public function it_allow_only_carbon_instance_as_expire_time() { $datetime = 1; - $this->shouldThrow('InvalidArgumentException')->during('expire',[$datetime]); + $this->shouldThrow('InvalidArgumentException')->during('expire', [$datetime]); } - /** @test */ - function it_add_a_category_id_to_the_builder() + public function it_add_a_category_id_to_the_builder() { $category_id = 1; @@ -120,7 +118,7 @@ function it_add_a_category_id_to_the_builder() } /** @test */ - function it_add_a_category_id_to_the_builder_givin_the_name_of_it(CategoryManager $category, NotificationCategory $categoryModel) + public function it_add_a_category_id_to_the_builder_givin_the_name_of_it(CategoryManager $category, NotificationCategory $categoryModel) { $name = 'category.name'; $category_id = 1; @@ -134,7 +132,7 @@ function it_add_a_category_id_to_the_builder_givin_the_name_of_it(CategoryManage } /** @test */ - function it_add_the_extra_parameter_to_the_builder() + public function it_add_the_extra_parameter_to_the_builder() { $extra = ['my' => 'extra']; @@ -142,20 +140,19 @@ function it_add_the_extra_parameter_to_the_builder() } /** @test */ - function it_allow_only_associative_array_as_extra_parameter_they_llbe_converted_in_jon() + public function it_allow_only_associative_array_as_extra_parameter_they_llbe_converted_in_jon() { $extra = ['my']; - $this->shouldThrow('InvalidArgumentException')->during('extra',[$extra]); + $this->shouldThrow('InvalidArgumentException')->during('extra', [$extra]); } /** @test */ - function it_create_a_builder_array_using_a_raw_closure() + public function it_create_a_builder_array_using_a_raw_closure() { date_default_timezone_set('UTC'); - $closure = function(NotifynderBuilder $builder) - { + $closure = function (NotifynderBuilder $builder) { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; @@ -169,16 +166,14 @@ function it_create_a_builder_array_using_a_raw_closure() public function it_create_multi_notification_in_a_loop() { - $closure = function(NotifynderBuilder $builder,$data,$key) - { + $closure = function (NotifynderBuilder $builder, $data, $key) { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; } public function it_create_empty_array_loop_builder() { - $closure = function(NotifynderBuilder $builder,$data,$key) - { + $closure = function (NotifynderBuilder $builder, $data, $key) { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; $this->shouldThrow(IterableIsEmptyException::class)->during('loop', [[], $closure]); @@ -186,8 +181,7 @@ public function it_create_empty_array_loop_builder() public function it_create_empty_collection_loop_builder() { - $closure = function(NotifynderBuilder $builder,$data,$key) - { + $closure = function (NotifynderBuilder $builder, $data, $key) { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; $this->shouldThrow(IterableIsEmptyException::class)->during('loop', [new Collection([]), $closure]); @@ -195,8 +189,7 @@ public function it_create_empty_collection_loop_builder() public function it_create_not_iterable_loop_builder() { - $closure = function(NotifynderBuilder $builder,$data,$key) - { + $closure = function (NotifynderBuilder $builder, $data, $key) { return $builder->to(1)->from(2)->url('notifynder.io')->category(1); }; $this->shouldThrow(EntityNotIterableException::class)->during('loop', ['hello world', $closure]); diff --git a/spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php b/spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php index 706debd..0c9ca34 100755 --- a/spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php +++ b/spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php @@ -6,11 +6,10 @@ use Fenos\Notifynder\Exceptions\CategoryNotFoundException; use Fenos\Notifynder\Models\NotificationCategory; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class CategoryManagerSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Categories\CategoryManager'); } @@ -21,7 +20,7 @@ public function let(CategoryDB $categoryRepository) } /** @test */ - function it_find_a_category_by_name(CategoryDB $categoryRepository) + public function it_find_a_category_by_name(CategoryDB $categoryRepository) { $nameCategory = 'test.category'; @@ -32,7 +31,7 @@ function it_find_a_category_by_name(CategoryDB $categoryRepository) } /** @test */ - function it_try_to_find_a_non_existing_category(CategoryDB $categoryRepository) + public function it_try_to_find_a_non_existing_category(CategoryDB $categoryRepository) { $nameCategory = 'test.category'; @@ -40,23 +39,23 @@ function it_try_to_find_a_non_existing_category(CategoryDB $categoryRepository) ->willReturn(null); $this->shouldThrow(CategoryNotFoundException::class) - ->during('findByName',[$nameCategory]); + ->during('findByName', [$nameCategory]); } /** @test */ - function it_store_a_category(CategoryDB $categoryRepository) + public function it_store_a_category(CategoryDB $categoryRepository) { $categoryName = 'hello'; $categoryText = 'wow'; - $categoryRepository->add($categoryName,$categoryText)->shouldBeCalled() + $categoryRepository->add($categoryName, $categoryText)->shouldBeCalled() ->willReturn(new NotificationCategory()); - $this->add($categoryName,$categoryText)->shouldReturnAnInstanceOf(NotificationCategory::class); + $this->add($categoryName, $categoryText)->shouldReturnAnInstanceOf(NotificationCategory::class); } /** @test */ - function it_delete_a_category_by_id(CategoryDB $categoryRepository) + public function it_delete_a_category_by_id(CategoryDB $categoryRepository) { $categoryId = 1; @@ -69,7 +68,7 @@ function it_delete_a_category_by_id(CategoryDB $categoryRepository) } /** @test */ - function it_delete_a_category_by_name(CategoryDB $categoryRepository) + public function it_delete_a_category_by_name(CategoryDB $categoryRepository) { $categoryName = 'testCategory'; diff --git a/spec/Fenos/Notifynder/Groups/GroupManagerSpec.php b/spec/Fenos/Notifynder/Groups/GroupManagerSpec.php index 0efc597..d451d4f 100755 --- a/spec/Fenos/Notifynder/Groups/GroupManagerSpec.php +++ b/spec/Fenos/Notifynder/Groups/GroupManagerSpec.php @@ -7,22 +7,21 @@ use Fenos\Notifynder\Exceptions\NotifynderGroupNotFoundException; use Fenos\Notifynder\Models\NotificationGroup; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class GroupManagerSpec extends ObjectBehavior { public function let(NotifynderGroupDB $groupDB, NotifynderGroupCategoryDB $groupCategoryDB) { - $this->beConstructedWith($groupDB,$groupCategoryDB); + $this->beConstructedWith($groupDB, $groupCategoryDB); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Groups\GroupManager'); } /** @test */ - function it_find_a_group_by_id(NotifynderGroupDB $groupDB, NotificationGroup $group) + public function it_find_a_group_by_id(NotifynderGroupDB $groupDB, NotificationGroup $group) { $group_id = 1; @@ -33,18 +32,18 @@ function it_find_a_group_by_id(NotifynderGroupDB $groupDB, NotificationGroup $gr } /** @test */ - function it_try_to_find_an_not_existing_group_by_id(NotifynderGroupDB $groupDB) + public function it_try_to_find_an_not_existing_group_by_id(NotifynderGroupDB $groupDB) { $group_id = 1; $groupDB->find($group_id)->shouldBeCalled() ->willReturn(null); - $this->shouldThrow(NotifynderGroupNotFoundException::class)->during('findById',[$group_id]); + $this->shouldThrow(NotifynderGroupNotFoundException::class)->during('findById', [$group_id]); } /** @test */ - function it_find_a_group_by_name(NotifynderGroupDB $groupDB, NotificationGroup $group) + public function it_find_a_group_by_name(NotifynderGroupDB $groupDB, NotificationGroup $group) { $group_name = 'mygroup'; @@ -55,56 +54,56 @@ function it_find_a_group_by_name(NotifynderGroupDB $groupDB, NotificationGroup $ } /** @test */ - function it_try_to_find_an_not_existing_group_by_name(NotifynderGroupDB $groupDB) + public function it_try_to_find_an_not_existing_group_by_name(NotifynderGroupDB $groupDB) { $group_name = 'mygroup'; $groupDB->findByName($group_name)->shouldBeCalled() ->willReturn(null); - $this->shouldThrow(NotifynderGroupNotFoundException::class)->during('findByName',[$group_name]); + $this->shouldThrow(NotifynderGroupNotFoundException::class)->during('findByName', [$group_name]); } /** @test */ - function it_add_a_category_to_a_group_by_id(NotifynderGroupCategoryDB $groupCategoryDB, NotificationGroup $group) + public function it_add_a_category_to_a_group_by_id(NotifynderGroupCategoryDB $groupCategoryDB, NotificationGroup $group) { $group_id = 1; $category_id = 2; - $groupCategoryDB->addCategoryToGroupById($group_id,$category_id)->shouldBeCalled() + $groupCategoryDB->addCategoryToGroupById($group_id, $category_id)->shouldBeCalled() ->willReturn($group); - $this->addCategoryToGroupById($group_id,$category_id)->shouldReturnAnInstanceOf(NotificationGroup::class); + $this->addCategoryToGroupById($group_id, $category_id)->shouldReturnAnInstanceOf(NotificationGroup::class); } /** @test */ - function it_add_a_category_to_a_group_by_name(NotifynderGroupCategoryDB $groupCategoryDB, NotificationGroup $group) + public function it_add_a_category_to_a_group_by_name(NotifynderGroupCategoryDB $groupCategoryDB, NotificationGroup $group) { $group_name = 'mygroup'; $category_name = 'mycategory'; - $groupCategoryDB->addCategoryToGroupByName($group_name,$category_name)->shouldBeCalled() + $groupCategoryDB->addCategoryToGroupByName($group_name, $category_name)->shouldBeCalled() ->willReturn($group); - $this->addCategoryToGroupByName($group_name,$category_name)->shouldReturnAnInstanceOf(NotificationGroup::class); + $this->addCategoryToGroupByName($group_name, $category_name)->shouldReturnAnInstanceOf(NotificationGroup::class); } /** @test */ - function it_add_multiple_categories_to_a_group(NotifynderGroupCategoryDB $groupCategoryDB) + public function it_add_multiple_categories_to_a_group(NotifynderGroupCategoryDB $groupCategoryDB) { $group_name = 'mygroup'; $category1 = 'mycategory1'; $category2 = 'mycategory2'; - $groupCategoryDB->addMultipleCategoriesToGroup($group_name,[$category1,$category2])->shouldBeCalled() + $groupCategoryDB->addMultipleCategoriesToGroup($group_name, [$category1, $category2])->shouldBeCalled() ->willReturn(2); - $this->addMultipleCategoriesToGroup($group_name,$category1,$category2) + $this->addMultipleCategoriesToGroup($group_name, $category1, $category2) ->shouldReturn(2); } /** @test */ - function it_add_a_group_in_the_db_respecting_convention(NotifynderGroupDB $groupDB,NotificationGroup $group) + public function it_add_a_group_in_the_db_respecting_convention(NotifynderGroupDB $groupDB, NotificationGroup $group) { $name = 'my.category'; @@ -115,10 +114,10 @@ function it_add_a_group_in_the_db_respecting_convention(NotifynderGroupDB $group } /** @test */ - function it_add_a_group_in_the_db_NOT_respecting_convention(NotifynderGroupDB $groupDB,NotificationGroup $group) + public function it_add_a_group_in_the_db_NOT_respecting_convention(NotifynderGroupDB $groupDB, NotificationGroup $group) { $name = 'mycategory'; // no dot as 'namespace' - $this->shouldThrow('InvalidArgumentException')->during('addGroup',[$name]); + $this->shouldThrow('InvalidArgumentException')->during('addGroup', [$name]); } } diff --git a/spec/Fenos/Notifynder/Handler/DispatcherSpec.php b/spec/Fenos/Notifynder/Handler/DispatcherSpec.php index 5e266ee..3bd1f92 100755 --- a/spec/Fenos/Notifynder/Handler/DispatcherSpec.php +++ b/spec/Fenos/Notifynder/Handler/DispatcherSpec.php @@ -6,7 +6,6 @@ use Fenos\Notifynder\NotifynderManager; use Illuminate\Contracts\Events\Dispatcher; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class DispatcherSpec extends ObjectBehavior { @@ -15,47 +14,47 @@ public function let(Dispatcher $dispatcher) $this->beConstructedWith($dispatcher); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Handler\Dispatcher'); } /** @test */ - function it_fire_a_notifynder_event(Dispatcher $dispatcher, NotifynderManager $notifynder) + public function it_fire_a_notifynder_event(Dispatcher $dispatcher, NotifynderManager $notifynder) { $key = 'event'; $category = 'hello'; $extraValues = []; $notifyEvent = 'Notifynder.'.$key; $notificationBuilt = [ - 0 => ['notification'] + 0 => ['notification'], ]; - $notifynderEvent = new NotifynderEvent($notifyEvent,$category,$extraValues); + $notifynderEvent = new NotifynderEvent($notifyEvent, $category, $extraValues); - $dispatcher->fire($notifyEvent,[$notifynderEvent,$notifynder])->shouldBeCalled() + $dispatcher->fire($notifyEvent, [$notifynderEvent, $notifynder])->shouldBeCalled() ->willReturn($notificationBuilt); $notifynder->send($notificationBuilt[0])->shouldBeCalled() ->willReturn(1); - $this->fire($notifynder,$key,$category,$extraValues)->shouldReturn(1); + $this->fire($notifynder, $key, $category, $extraValues)->shouldReturn(1); } /** @test */ - function it_fire_a_notifynder_event_having_nothing_to_send(Dispatcher $dispatcher, NotifynderManager $notifynder) + public function it_fire_a_notifynder_event_having_nothing_to_send(Dispatcher $dispatcher, NotifynderManager $notifynder) { $key = 'event'; $category = 'hello'; $extraValues = []; $notifyEvent = 'Notifynder.'.$key; - $notifynderEvent = new NotifynderEvent($notifyEvent,$category,$extraValues); + $notifynderEvent = new NotifynderEvent($notifyEvent, $category, $extraValues); - $dispatcher->fire($notifyEvent,[$notifynderEvent,$notifynder])->shouldBeCalled() + $dispatcher->fire($notifyEvent, [$notifynderEvent, $notifynder])->shouldBeCalled() ->willReturn(null); - $this->fire($notifynder,$key,$category,$extraValues) + $this->fire($notifynder, $key, $category, $extraValues) ->shouldReturn(null); } } diff --git a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php b/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php index 8da619c..6a510eb 100755 --- a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php +++ b/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php @@ -6,10 +6,7 @@ use Fenos\Notifynder\Exceptions\NotificationNotFoundException; use Fenos\Notifynder\Models\Notification; use Fenos\Notifynder\Models\NotifynderCollection; -use Illuminate\Contracts\Config\Repository; -use Illuminate\Database\Eloquent\Collection; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class NotificationManagerSpec extends ObjectBehavior { @@ -18,13 +15,13 @@ public function let(NotificationDB $notificationRepo) $this->beConstructedWith($notificationRepo); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Notifications\NotificationManager'); } /** @test */ - function it_find_a_notification_by_id(NotificationDB $notificationRepo) + public function it_find_a_notification_by_id(NotificationDB $notificationRepo) { $notification_id = 1; $notification = new Notification(); @@ -36,18 +33,18 @@ function it_find_a_notification_by_id(NotificationDB $notificationRepo) } /** @test */ - function it_try_to_find_an_inexistent_notification(NotificationDB $notificationRepo) + public function it_try_to_find_an_inexistent_notification(NotificationDB $notificationRepo) { $notification_id = 1; $notificationRepo->find($notification_id)->shouldBeCalled() ->willReturn(null); - $this->shouldThrow(NotificationNotFoundException::class)->during('find',[$notification_id]); + $this->shouldThrow(NotificationNotFoundException::class)->during('find', [$notification_id]); } /** @test */ - function it_read_one_notification_by_id(NotificationDB $notificationRepo) + public function it_read_one_notification_by_id(NotificationDB $notificationRepo) { $notification_id = 1; $notification = new Notification(); @@ -62,33 +59,33 @@ function it_read_one_notification_by_id(NotificationDB $notificationRepo) } /** @test */ - function it_read_notifications_limit_to_a_given_number(NotificationDB $notificationRepo) + public function it_read_notifications_limit_to_a_given_number(NotificationDB $notificationRepo) { $to_id = 1; $numbers = 5; $order = 'asc'; - $notificationRepo->readLimit($to_id,null,$numbers,$order)->shouldBeCalled() + $notificationRepo->readLimit($to_id, null, $numbers, $order)->shouldBeCalled() ->willReturn($numbers); - $this->readLimit($to_id,$numbers,$order)->shouldReturn($numbers); + $this->readLimit($to_id, $numbers, $order)->shouldReturn($numbers); } /** @test */ - function it_read_all_notification_of_the_given_entity(NotificationDB $notificationRepo) + public function it_read_all_notification_of_the_given_entity(NotificationDB $notificationRepo) { $id = 1; $entity = null; $notificationDeleted = 10; - $notificationRepo->readAll($id,$entity)->shouldBeCalled() + $notificationRepo->readAll($id, $entity)->shouldBeCalled() ->willReturn($notificationDeleted); $this->readAll($id)->shouldReturn($notificationDeleted); } /** @test */ - function it_delete_a_notification_by_id(NotificationDB $notificationRepo) + public function it_delete_a_notification_by_id(NotificationDB $notificationRepo) { $notification_id = 1; @@ -99,83 +96,83 @@ function it_delete_a_notification_by_id(NotificationDB $notificationRepo) } /** @test */ - function it_delete_notification_limiting_the_number_of_the_given_entity(NotificationDB $notificationRepo) + public function it_delete_notification_limiting_the_number_of_the_given_entity(NotificationDB $notificationRepo) { $entity_id = 1; $numberLimit = 5; $order = 'asc'; - $notificationRepo->deleteLimit($entity_id,null,$numberLimit,$order)->shouldBeCalled() + $notificationRepo->deleteLimit($entity_id, null, $numberLimit, $order)->shouldBeCalled() ->willReturn($numberLimit); - $this->deleteLimit($entity_id,$numberLimit,$order)->shouldReturn($numberLimit); + $this->deleteLimit($entity_id, $numberLimit, $order)->shouldReturn($numberLimit); } /** @test */ - function it_delete_all_notification_of_the_given_entity(NotificationDB $notificationRepo) + public function it_delete_all_notification_of_the_given_entity(NotificationDB $notificationRepo) { $entity_id = 1; $notificationsDeleted = 10; - $notificationRepo->deleteAll($entity_id,null)->shouldBeCalled() + $notificationRepo->deleteAll($entity_id, null)->shouldBeCalled() ->willReturn($notificationsDeleted); $this->deleteAll($entity_id)->shouldReturn($notificationsDeleted); } /** @test */ - function it_get_not_read_notification(NotificationDB $notificationRepo,NotifynderCollection $collection) + public function it_get_not_read_notification(NotificationDB $notificationRepo, NotifynderCollection $collection) { $entity_id = 1; $limit = 10; $paginate = null; - $notificationRepo->getNotRead($entity_id,null,$limit,$paginate,'desc',null)->shouldBeCalled() + $notificationRepo->getNotRead($entity_id, null, $limit, $paginate, 'desc', null)->shouldBeCalled() ->willReturn($collection); $collection->parse()->shouldBeCalled()->willReturn([]); - $this->getNotRead($entity_id,$limit,$paginate,'desc')->shouldReturn([]); + $this->getNotRead($entity_id, $limit, $paginate, 'desc')->shouldReturn([]); } /** @test */ - function it_get_all_notifications_of_the_given_entity(NotificationDB $notificationRepo,NotifynderCollection $collection) + public function it_get_all_notifications_of_the_given_entity(NotificationDB $notificationRepo, NotifynderCollection $collection) { $entity_id = 1; $limit = 10; $paginate = null; - $notificationRepo->getAll($entity_id,null,$limit,$paginate,'desc',null)->shouldBeCalled() + $notificationRepo->getAll($entity_id, null, $limit, $paginate, 'desc', null)->shouldBeCalled() ->willReturn($collection); $collection->parse()->shouldBeCalled()->willReturn([]); - $this->getAll($entity_id,$limit,$paginate)->shouldReturn([]); + $this->getAll($entity_id, $limit, $paginate)->shouldReturn([]); } /** @test */ - function it_get_last_notification_of_the_current_entity(NotificationDB $notificationRepo) + public function it_get_last_notification_of_the_current_entity(NotificationDB $notificationRepo) { $id = 1; - $notificationRepo->getLastNotification($id,null,null)->shouldBeCalled()->willReturn(new Notification()); + $notificationRepo->getLastNotification($id, null, null)->shouldBeCalled()->willReturn(new Notification()); $this->getLastNotification($id)->shouldReturnAnInstanceOf(Notification::class); } /** @test */ - function it_get_last_notification_of_the_current_entity_filtering_by_category(NotificationDB $notificationRepo) + public function it_get_last_notification_of_the_current_entity_filtering_by_category(NotificationDB $notificationRepo) { $id = 1; $category = 'notifynder.category'; - $notificationRepo->getLastNotificationByCategory($category,$id,null,null)->shouldBeCalled()->willReturn(new Notification()); + $notificationRepo->getLastNotificationByCategory($category, $id, null, null)->shouldBeCalled()->willReturn(new Notification()); - $this->getLastNotificationByCategory($category,$id)->shouldReturnAnInstanceOf(Notification::class); + $this->getLastNotificationByCategory($category, $id)->shouldReturnAnInstanceOf(Notification::class); } /** @test */ - function it_send_a_single_notification(NotificationDB $notificationRepo) + public function it_send_a_single_notification(NotificationDB $notificationRepo) { $notificationData = []; $notification = new Notification(); @@ -187,7 +184,7 @@ function it_send_a_single_notification(NotificationDB $notificationRepo) } /** @test */ - function it_send_multiple_notification(NotificationDB $notificationRepo) + public function it_send_multiple_notification(NotificationDB $notificationRepo) { $notificationData = []; $notificationsSent = 5; @@ -199,23 +196,23 @@ function it_send_multiple_notification(NotificationDB $notificationRepo) } /** @test */ - function it_count_notification_not_read(NotificationDB $notificationRepo) + public function it_count_notification_not_read(NotificationDB $notificationRepo) { $entity_id = 1; $notificationCount = 10; - $notificationRepo->countNotRead($entity_id,null,null)->shouldBeCalled() + $notificationRepo->countNotRead($entity_id, null, null)->shouldBeCalled() ->willReturn($notificationCount); $this->countNotRead($entity_id)->shouldReturn($notificationCount); } /** @test */ - function it_delete_notification_by_categories(NotificationDB $notificationRepo) + public function it_delete_notification_by_categories(NotificationDB $notificationRepo) { $categoryName = 'notifynder.test'; - $notificationRepo->deleteByCategory($categoryName,false)->shouldBeCalled() + $notificationRepo->deleteByCategory($categoryName, false)->shouldBeCalled() ->willReturn(1); $this->deleteByCategory($categoryName)->shouldReturn(1); diff --git a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php index 756cfb9..79c31c4 100755 --- a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php +++ b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php @@ -5,77 +5,76 @@ use Fenos\Notifynder\Exceptions\ExtraParamsException; use Fenos\Notifynder\Parsers\NotifynderParser; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class NotifynderParserSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Parsers\NotifynderParser'); } /** @test */ - function it_should_replace_special_values_with_an_associative_array() + public function it_should_replace_special_values_with_an_associative_array() { $extra = ['hello' => 'world']; $notification = [ 'body' => [ - 'text' => 'Hi jhon hello {extra.hello}' + 'text' => 'Hi jhon hello {extra.hello}', ], - 'extra' => json_encode($extra) + 'extra' => json_encode($extra), ]; $this->parse($notification)->shouldReturn('Hi jhon hello world'); } /** @test */ - function it_replace_from_values_relations() + public function it_replace_from_values_relations() { $notification = [ 'body' => [ - 'text' => 'Hi {to.username} hello' + 'text' => 'Hi {to.username} hello', ], 'to' => [ 'username' => 'jhon', ], - 'extra' => null + 'extra' => null, ]; $this->parse($notification)->shouldReturn('Hi jhon hello'); } /** @test */ - function it_replace_both_in_a_string() + public function it_replace_both_in_a_string() { $extra = ['hello' => 'world']; $notification = [ 'body' => [ - 'text' => 'Hi {to.username} hello {extra.hello}' + 'text' => 'Hi {to.username} hello {extra.hello}', ], 'to' => [ 'username' => 'jhon', ], - 'extra' => json_encode($extra) + 'extra' => json_encode($extra), ]; $this->parse($notification)->shouldReturn('Hi jhon hello world'); } /** @test */ - function it_will_remove_extra_markup_if_extra_value_is_not_provided() + public function it_will_remove_extra_markup_if_extra_value_is_not_provided() { $extra = []; $notification = [ 'body' => [ - 'text' => 'Hi {to.username} hello {extra.hello}' + 'text' => 'Hi {to.username} hello {extra.hello}', ], 'to' => [ 'username' => 'jhon', ], - 'extra' => json_encode($extra) + 'extra' => json_encode($extra), ]; // note the space, TODO: shall i remove it? @@ -83,45 +82,45 @@ function it_will_remove_extra_markup_if_extra_value_is_not_provided() } /** @test */ - function it_will_throw_exception_when_strict_extra_is_enabled() + public function it_will_throw_exception_when_strict_extra_is_enabled() { $extra = null; $notification = [ 'body' => [ - 'text' => 'Hi {to.username} hello {extra.hello}' + 'text' => 'Hi {to.username} hello {extra.hello}', ], 'to' => [ 'username' => 'jhon', ], - 'extra' => json_encode($extra) + 'extra' => json_encode($extra), ]; NotifynderParser::setStrictExtra(true); $this->shouldThrow(ExtraParamsException::class) - ->during('parse',[$notification]); + ->during('parse', [$notification]); } /** @test */ - function it_will_parse_4_extra_params() + public function it_will_parse_4_extra_params() { $extra = [ 'name' => 'fabri', 'username' => 'fenos', 'status' => 'active', - 'prof' => 'dev' + 'prof' => 'dev', ]; $text = 'Hi {extra.name}, your username is: {extra.username} your status: {extra.status} your profession: {extra.prof}'; $notification = [ 'body' => [ - 'text' => $text + 'text' => $text, ], - 'extra' => json_encode($extra) + 'extra' => json_encode($extra), ]; $parsedText = "Hi {$extra['name']}, your username is: {$extra['username']} your status: {$extra['status']} your profession: {$extra['prof']}"; $this->parse($notification)->shouldReturn($parsedText); } -} \ No newline at end of file +} diff --git a/spec/Fenos/Notifynder/Senders/SendMultipleSpec.php b/spec/Fenos/Notifynder/Senders/SendMultipleSpec.php index b4ba957..df1938f 100755 --- a/spec/Fenos/Notifynder/Senders/SendMultipleSpec.php +++ b/spec/Fenos/Notifynder/Senders/SendMultipleSpec.php @@ -4,7 +4,6 @@ use Fenos\Notifynder\Contracts\StoreNotification; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class SendMultipleSpec extends ObjectBehavior { @@ -14,13 +13,13 @@ public function let() $this->beConstructedWith($notifications); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Senders\SendMultiple'); } /** @test */ - function it_send_multiple_notification(StoreNotification $storeNotification) + public function it_send_multiple_notification(StoreNotification $storeNotification) { $multiple = [ ]; diff --git a/spec/Fenos/Notifynder/Senders/SendOneSpec.php b/spec/Fenos/Notifynder/Senders/SendOneSpec.php index f777dc3..26085a0 100755 --- a/spec/Fenos/Notifynder/Senders/SendOneSpec.php +++ b/spec/Fenos/Notifynder/Senders/SendOneSpec.php @@ -6,7 +6,6 @@ use Fenos\Notifynder\Exceptions\CategoryNotFoundException; use Fenos\Notifynder\Models\Notification; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class SendOneSpec extends ObjectBehavior { @@ -16,16 +15,16 @@ public function let() $this->beConstructedWith($infoNotification); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Senders\SendOne'); } /** @test */ - function it_send_a_single_notification_having_the_category_(StoreNotification $storeNotification) + public function it_send_a_single_notification_having_the_category_(StoreNotification $storeNotification) { $infoNotification = [ - 'category_id' => 1 + 'category_id' => 1, ]; $this->beConstructedWith($infoNotification); @@ -37,10 +36,10 @@ function it_send_a_single_notification_having_the_category_(StoreNotification $s } /** @test */ - function it_try_to_send_a_notification_without_category_id(StoreNotification $storeNotification) + public function it_try_to_send_a_notification_without_category_id(StoreNotification $storeNotification) { // throw exception because I didn't specified a category_id $this->shouldThrow(CategoryNotFoundException::class) - ->during('send',[$storeNotification]); + ->during('send', [$storeNotification]); } } diff --git a/spec/Fenos/Notifynder/Senders/SenderFactorySpec.php b/spec/Fenos/Notifynder/Senders/SenderFactorySpec.php index 6920c3b..c55f7e8 100755 --- a/spec/Fenos/Notifynder/Senders/SenderFactorySpec.php +++ b/spec/Fenos/Notifynder/Senders/SenderFactorySpec.php @@ -8,50 +8,49 @@ use Fenos\Notifynder\Senders\SendMultiple; use Fenos\Notifynder\Senders\SendOne; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class SenderFactorySpec extends ObjectBehavior { public function let(NotifynderGroup $notifynderGroup, NotifynderCategory $notifynderCategory) { - $this->beConstructedWith($notifynderGroup,$notifynderCategory); + $this->beConstructedWith($notifynderGroup, $notifynderCategory); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Senders\SenderFactory'); } /** @test */ - function it_get_a_dynamic_sender_checking_array_type_GET_SINGLE() + public function it_get_a_dynamic_sender_checking_array_type_GET_SINGLE() { // if the array is multidimensional then // send multiple $notification = []; $category = 1; - $this->getSender($notification,$category)->shouldReturnAnInstanceOf(SendOne::class); + $this->getSender($notification, $category)->shouldReturnAnInstanceOf(SendOne::class); } /** @test */ - function it_get_a_dynamic_sender_checking_array_type_GET_MULTIPLE() + public function it_get_a_dynamic_sender_checking_array_type_GET_MULTIPLE() { // if the array is multidimensional then // send multiple $notification = [ - 0 => [] + 0 => [], ]; $category = 1; - $this->getSender($notification,$category)->shouldReturnAnInstanceOf(SendMultiple::class); + $this->getSender($notification, $category)->shouldReturnAnInstanceOf(SendMultiple::class); } /** @test */ - function it_get_the_send_group_sender() + public function it_get_the_send_group_sender() { $group_name = 'mygroup'; $info = []; - $this->sendGroup($group_name,$info)->shouldReturnAnInstanceOf(SendGroup::class); + $this->sendGroup($group_name, $info)->shouldReturnAnInstanceOf(SendGroup::class); } } diff --git a/spec/Fenos/Notifynder/Senders/SenderManagerSpec.php b/spec/Fenos/Notifynder/Senders/SenderManagerSpec.php index 3c92ef5..744c085 100755 --- a/spec/Fenos/Notifynder/Senders/SenderManagerSpec.php +++ b/spec/Fenos/Notifynder/Senders/SenderManagerSpec.php @@ -8,56 +8,55 @@ use Fenos\Notifynder\Senders\SenderFactory; use Illuminate\Contracts\Foundation\Application; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class SenderManagerSpec extends ObjectBehavior { public function let(SenderFactory $senderFactory, StoreNotification $storeNotification, Application $application) { - $this->beConstructedWith($senderFactory,$storeNotification,$application); + $this->beConstructedWith($senderFactory, $storeNotification, $application); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Senders\SenderManager'); } /** @test */ - function it_send_now_a_notification(SenderFactory $senderFactory, + public function it_send_now_a_notification(SenderFactory $senderFactory, DefaultSender $sender, StoreNotification $storeNotification) { $notifications = []; $category = 1; - $senderFactory->getSender($notifications,$category)->shouldBeCalled() + $senderFactory->getSender($notifications, $category)->shouldBeCalled() ->willReturn($sender); $sender->send($storeNotification)->shouldBeCalled() ->willReturn(1); - $this->sendNow($notifications,$category)->shouldReturn(1); + $this->sendNow($notifications, $category)->shouldReturn(1); } /** @test */ - function it_send_one_notification(SenderFactory $senderFactory, + public function it_send_one_notification(SenderFactory $senderFactory, DefaultSender $sender, StoreNotification $storeNotification) { $notifications = []; $category = 1; - $senderFactory->sendSingle($notifications,$category)->shouldBeCalled() + $senderFactory->sendSingle($notifications, $category)->shouldBeCalled() ->willReturn($sender); - $sender->send($storeNotification,$category)->shouldBeCalled() + $sender->send($storeNotification, $category)->shouldBeCalled() ->willReturn(1); - $this->sendOne($notifications,$category)->shouldReturn(1); + $this->sendOne($notifications, $category)->shouldReturn(1); } /** @test */ - function it_send_multiple_notification(SenderFactory $senderFactory, + public function it_send_multiple_notification(SenderFactory $senderFactory, DefaultSender $sender, StoreNotification $storeNotification) { @@ -73,13 +72,13 @@ function it_send_multiple_notification(SenderFactory $senderFactory, } /** @test */ - function it_call_an_extended_method(SenderFactory $senderFactory, + public function it_call_an_extended_method(SenderFactory $senderFactory, DefaultSender $sender, StoreNotification $storeNotification) { $notifications = []; - $this->extend('sendExtended', function($app) use ($sender){ + $this->extend('sendExtended', function ($app) use ($sender) { return new TestExtender(); }); @@ -87,9 +86,9 @@ function it_call_an_extended_method(SenderFactory $senderFactory, } /** @test */ - function it_try_to_call_an_inexistent_extended_method() + public function it_try_to_call_an_inexistent_extended_method() { - $this->shouldThrow(BadMethodCallException::class)->during('NotExistingExtender',[]); + $this->shouldThrow(BadMethodCallException::class)->during('NotExistingExtender', []); } } @@ -102,9 +101,8 @@ function it_try_to_call_an_inexistent_extended_method() class TestExtender implements DefaultSender { - /** - * Send Single notification + * Send Single notification. * * @param StoreNotification $sender * @return mixed @@ -113,4 +111,4 @@ public function send(StoreNotification $sender) { return []; } -} \ No newline at end of file +} diff --git a/spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php b/spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php index 3de3a62..a16d877 100755 --- a/spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php +++ b/spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php @@ -7,29 +7,28 @@ use Fenos\Notifynder\Translator\Compiler; use Illuminate\Contracts\Config\Repository; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class TranslatorManagerSpec extends ObjectBehavior { public function let(Compiler $compiler, Repository $config) { - $this->beConstructedWith($compiler,$config); + $this->beConstructedWith($compiler, $config); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Fenos\Notifynder\Translator\TranslatorManager'); } /** @test */ - function it_translate_the_given_category_in_the_given_language(Compiler $compiler, Repository $config) + public function it_translate_the_given_category_in_the_given_language(Compiler $compiler, Repository $config) { $filePath = 'cached/file'; $categoryToTranslate = 'categoryName'; $translations = [ 'it' => [ - $categoryToTranslate => 'translation' - ] + $categoryToTranslate => 'translation', + ], ]; $compiler->getFilePath()->shouldBeCalled() @@ -40,20 +39,19 @@ function it_translate_the_given_category_in_the_given_language(Compiler $compile $compiler->cacheFile($translations)->shouldBeCalled(); - $this->translate('it', $categoryToTranslate) ->shouldReturn($translations['it'][$categoryToTranslate]); } /** @test */ - function it__try_to_translate_the_given_category(Compiler $compiler, Repository $config) + public function it__try_to_translate_the_given_category(Compiler $compiler, Repository $config) { $filePath = 'cached/file'; $categoryToTranslate = 'categoryName'; $translations = [ 'it' => [ - $categoryToTranslate => 'translation' - ] + $categoryToTranslate => 'translation', + ], ]; $compiler->getFilePath()->shouldBeCalled() @@ -65,17 +63,17 @@ function it__try_to_translate_the_given_category(Compiler $compiler, Repository $compiler->cacheFile($translations)->shouldBeCalled(); $this->shouldThrow(NotificationTranslationNotFoundException::class) - ->during('translate',['it','not existing']); + ->during('translate', ['it', 'not existing']); } /** @test */ - function it_get_a_language_from_the_translations(Compiler $compiler, Repository $config) + public function it_get_a_language_from_the_translations(Compiler $compiler, Repository $config) { $filePath = 'cached/file'; $translations = [ 'it' => [ - 'categoryName' => 'translation' - ] + 'categoryName' => 'translation', + ], ]; $compiler->getFilePath()->shouldBeCalled() @@ -90,13 +88,13 @@ function it_get_a_language_from_the_translations(Compiler $compiler, Repository } /** @test */ - function it__try_to_get_a_language_from_the_translations(Compiler $compiler, Repository $config) + public function it__try_to_get_a_language_from_the_translations(Compiler $compiler, Repository $config) { $filePath = 'cached/file'; $translations = [ 'it' => [ - 'categoryName' => 'translation' - ] + 'categoryName' => 'translation', + ], ]; $compiler->getFilePath()->shouldBeCalled() @@ -108,11 +106,11 @@ function it__try_to_get_a_language_from_the_translations(Compiler $compiler, Rep $compiler->cacheFile($translations)->shouldBeCalled(); $this->shouldThrow(NotificationLanguageNotFoundException::class) - ->during('getLanguage',['en']); + ->during('getLanguage', ['en']); } /** @test */ - function it_get_the_translations_from_never_cached_config_file(Compiler $compiler, Repository $config) + public function it_get_the_translations_from_never_cached_config_file(Compiler $compiler, Repository $config) { $filePath = 'cached/file'; $translations = []; diff --git a/src/Notifynder/Artisan/CreateCategory.php b/src/Notifynder/Artisan/CreateCategory.php index 1639f0f..d3f00e4 100755 --- a/src/Notifynder/Artisan/CreateCategory.php +++ b/src/Notifynder/Artisan/CreateCategory.php @@ -1,4 +1,6 @@ -notifynderGroup - ->addMultipleCategoriesToGroup($categoryGroup,$categories); + ->addMultipleCategoriesToGroup($categoryGroup, $categories); if ($groupCategories) { foreach ($groupCategories->categories as $category) { @@ -96,9 +97,9 @@ public function getArgumentsConsole() */ protected function getArguments() { - return array( - array('name', InputArgument::REQUIRED, 'user.post.add'), - ); + return [ + ['name', InputArgument::REQUIRED, 'user.post.add'], + ]; } /** @@ -108,8 +109,8 @@ protected function getArguments() */ protected function getOptions() { - return array( - array('categories', null, InputOption::VALUE_OPTIONAL, 'notifynder.name', []), - ); + return [ + ['categories', null, InputOption::VALUE_OPTIONAL, 'notifynder.name', []], + ]; } } diff --git a/src/Notifynder/Builder/BuilderRules.php b/src/Notifynder/Builder/BuilderRules.php index d48e6b4..1211b1f 100755 --- a/src/Notifynder/Builder/BuilderRules.php +++ b/src/Notifynder/Builder/BuilderRules.php @@ -1,28 +1,27 @@ -config instanceof Repository) { + if (property_exists($this, 'config') && $this->config instanceof Repository) { $customRequiredFields = $this->config->get('notifynder.additional_fields.required'); } else { $customRequiredFields = []; @@ -83,7 +84,7 @@ public function getRequiredFields() /** * Check that the builder has * the required field to send the - * notifications correctly + * notifications correctly. * * @param $array * @return bool @@ -100,28 +101,28 @@ public function hasRequiredFields($array) } /** - * Check if is a required field + * Check if is a required field. * * @param $offset * @return bool */ public function isRequiredField($offset) { - return (in_array($offset,$this->getRequiredFields())); + return in_array($offset, $this->getRequiredFields()); } /** * Check if the array passed is - * multidimensional + * multidimensional. * * @param $arr * @return bool */ protected function isReadyArrToFormatInJson(array $arr) { - if ($this->isAssociativeArr($arr)) { - return true; - } + if ($this->isAssociativeArr($arr)) { + return true; + } if (count($arr) > 0) { $error = "The 'extra' value must to be an associative array"; @@ -142,7 +143,7 @@ protected function isAssociativeArr(array $arr) /** * Check if the array is - * multidimensional + * multidimensional. * * @param $arr * @return bool diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index 8ffa213..e609f74 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -1,4 +1,6 @@ -notifynderCategory = $notifynderCategory; } /** - * Set who will send the notification + * Set who will send the notification. * * @return $this */ @@ -70,7 +70,7 @@ public function from() } /** - * Set who will receive the notification + * Set who will receive the notification. * * @return $this */ @@ -84,7 +84,7 @@ public function to() } /** - * Set the url of the notification + * Set the url of the notification. * * @param $url * @return $this @@ -99,7 +99,7 @@ public function url($url) } /** - * Set expire time + * Set expire time. * * @param $datetime * @return $this @@ -114,14 +114,14 @@ public function expire($datetime) /** * Set Category and covert it, to the id - * if name of it given + * if name of it given. * * @param $category * @return $this */ public function category($category) { - if (!is_numeric($category)) { + if (! is_numeric($category)) { $category = $this->notifynderCategory ->findByName($category)->id; } @@ -132,7 +132,7 @@ public function category($category) } /** - * Set extra value + * Set extra value. * * @param $extra * @return $this @@ -151,7 +151,7 @@ public function extra(array $extra = []) /** * Build the array with the builder inside * a Closure, it has more flexibility for - * the generation of your array + * the generation of your array. * * * @param callable|Closure $closure @@ -171,7 +171,7 @@ public function raw(Closure $closure) /** * Loop the datas for create - * multi notifications array + * multi notifications array. * * @param $dataToIterate * @param Closure $builder @@ -182,7 +182,7 @@ public function raw(Closure $closure) public function loop($dataToIterate, Closure $builder) { if ($this->isIterable($dataToIterate)) { - if(count($dataToIterate) > 0) { + if (count($dataToIterate) > 0) { $notifications = []; $newBuilder = new self($this->notifynderCategory); @@ -193,6 +193,7 @@ public function loop($dataToIterate, Closure $builder) } $this->notifications = $notifications; + return $this; } else { throw new IterableIsEmptyException('The Iterable passed must contain at least one element'); @@ -204,7 +205,7 @@ public function loop($dataToIterate, Closure $builder) /** * Compose the builder to - * the array + * the array. * * @throws NotificationBuilderException * @return mixed @@ -216,7 +217,6 @@ public function toArray() // If the builder is handling a single notification // we will validate only it if (! $hasMultipleNotifications) { - $this->setDate(); if ($this->hasRequiredFields($this->notifications)) { @@ -227,24 +227,23 @@ public function toArray() // If has multiple Notifications // we will validate one by one if ($hasMultipleNotifications) { - $allow = []; - foreach($this->notifications as $index => $notification) { + foreach ($this->notifications as $index => $notification) { $allow[$index] = $this->hasRequiredFields($notification); } - if (! in_array(false,$allow)) { + if (! in_array(false, $allow)) { return $this->notifications; } } - $error = "The fields: ".implode(',', $this->getRequiredFields())." are required"; + $error = 'The fields: '.implode(',', $this->getRequiredFields()).' are required'; throw new NotificationBuilderException($error); } /** - * Refresh the state of the notifications + * Refresh the state of the notifications. */ public function refresh() { @@ -259,13 +258,13 @@ public function refresh() */ protected function isIterable($var) { - return (is_array($var) || $var instanceof Traversable); + return is_array($var) || $var instanceof Traversable; } /** * It set the entity who will do * the action of receive or - * send + * send. * * @param $from * @param $property @@ -281,7 +280,7 @@ protected function setEntityAction($from, $property) $this->setBuilderData("{$property}_type", $from[0]); $this->setBuilderData("{$property}_id", $from[1]); - } elseif($from[0] instanceof Model) { + } elseif ($from[0] instanceof Model) { $this->setBuilderData("{$property}_type", $from[0]->getMorphClass()); $this->setBuilderData("{$property}_id", $from[0]->getKey()); } else { @@ -293,7 +292,7 @@ protected function setEntityAction($from, $property) /** * If the values passed are 2 or more, * it means that you spefied the entity - * over then the id + * over then the id. * * @param array $info * @return bool @@ -304,7 +303,7 @@ protected function hasEntity(array $info) } /** - * Set date on the array + * Set date on the array. */ protected function setDate() { @@ -323,7 +322,7 @@ protected function getDate() } /** - * Set builder Data + * Set builder Data. * * @param $field * @param $data @@ -333,17 +332,15 @@ public function setBuilderData($field, $data) return $this->notifications[$field] = $data; } - /** * @param mixed $offset * @return bool */ public function offsetExists($offset) { - return array_key_exists($offset,$this->notifications); + return array_key_exists($offset, $this->notifications); } - /** * @param mixed $offset * @return mixed @@ -353,7 +350,6 @@ public function offsetGet($offset) return $this->notifications[$offset]; } - /** * @param mixed $offset * @param mixed $value @@ -361,7 +357,6 @@ public function offsetGet($offset) public function offsetSet($offset, $value) { if (method_exists($this, $offset)) { - return $this->{$offset}($value); } diff --git a/src/Notifynder/Categories/CategoryManager.php b/src/Notifynder/Categories/CategoryManager.php index a949f83..de01646 100755 --- a/src/Notifynder/Categories/CategoryManager.php +++ b/src/Notifynder/Categories/CategoryManager.php @@ -1,20 +1,19 @@ -categoryRepo->findByName($name); if (is_null($category)) { - $error = "Category Not Found"; + $error = 'Category Not Found'; throw new CategoryNotFoundException($error); } @@ -49,7 +48,7 @@ public function findByName($name) /** * Find categories by names, - * pass the name as an array + * pass the name as an array. * * @param $name * @throws CategoryNotFoundException @@ -60,7 +59,7 @@ public function findByNames(array $name) $category = $this->categoryRepo->findByNames($name); if (count($category) == 0) { - $error = "Category Not Found"; + $error = 'Category Not Found'; throw new CategoryNotFoundException($error); } @@ -68,7 +67,7 @@ public function findByNames(array $name) } /** - * Find a category by id + * Find a category by id. * * @param $id * @throws CategoryNotFoundException @@ -79,7 +78,7 @@ public function find($id) $category = $this->categoryRepo->find($id); if (is_null($category)) { - $error = "Category Not Found"; + $error = 'Category Not Found'; throw new CategoryNotFoundException($error); } @@ -87,7 +86,7 @@ public function find($id) } /** - * Add a category to the DB + * Add a category to the DB. * * @param array $name * @param $text @@ -99,7 +98,7 @@ public function add($name, $text) } /** - * Delete category by ID + * Delete category by ID. * * @param $id * @return mixed @@ -110,7 +109,7 @@ public function delete($id) } /** - * Delete category by name + * Delete category by name. * * @param $name * @return mixed @@ -121,7 +120,7 @@ public function deleteByName($name) } /** - * Update a category + * Update a category. * * @param array $data * @param $id diff --git a/src/Notifynder/Categories/CategoryRepository.php b/src/Notifynder/Categories/CategoryRepository.php index 1bb4462..da1457f 100755 --- a/src/Notifynder/Categories/CategoryRepository.php +++ b/src/Notifynder/Categories/CategoryRepository.php @@ -1,20 +1,19 @@ - 'text to translate' * ] * ] - * - * @package Fenos\Notifynder\Translator */ interface NotifynderTranslator { - /** - * Translate the given category + * Translate the given category. * * @param $language * @param $nameCategory @@ -36,7 +35,7 @@ interface NotifynderTranslator public function translate($language, $nameCategory); /** - * Get selected language of tranlsations + * Get selected language of tranlsations. * * @param $language * @return mixed @@ -45,7 +44,7 @@ public function translate($language, $nameCategory); public function getLanguage($language); /** - * Get translations + * Get translations. * * @return array|mixed */ diff --git a/src/Notifynder/Contracts/Sender.php b/src/Notifynder/Contracts/Sender.php index 3088526..9596e1e 100755 --- a/src/Notifynder/Contracts/Sender.php +++ b/src/Notifynder/Contracts/Sender.php @@ -1,17 +1,17 @@ -groupRepo->find($group_id); if (is_null($group)) { - $error = "Group Not Found"; + $error = 'Group Not Found'; throw new NotifynderGroupNotFoundException($error); } @@ -55,7 +54,7 @@ public function findById($group_id) } /** - * Find a group By name + * Find a group By name. * * @param $group_name * @return mixed @@ -66,7 +65,7 @@ public function findByName($group_name) $group = $this->groupRepo->findByName($group_name); if (is_null($group)) { - $error = "Group Not Found"; + $error = 'Group Not Found'; throw new NotifynderGroupNotFoundException($error); } @@ -75,7 +74,7 @@ public function findByName($group_name) /** * Add category to a group - * giving the ids of them + * giving the ids of them. * * @param $gorup_id * @param $category_id @@ -88,7 +87,7 @@ public function addCategoryToGroupById($gorup_id, $category_id) /** * Add category to a group - * giving the ids of them + * giving the ids of them. * * @param $gorup_name * @param $category_name @@ -102,7 +101,7 @@ public function addCategoryToGroupByName($gorup_name, $category_name) /** * Add Multiple categories in a group * First parameter is the group name - * all the rest are categories + * all the rest are categories. * * @return mixed */ @@ -119,7 +118,7 @@ public function addMultipleCategoriesToGroup() } /** - * Add a group in the db + * Add a group in the db. * * @param $name * @throws InvalidArgumentException @@ -131,12 +130,12 @@ public function addGroup($name) return $this->groupRepo->create($name); } - $error = "The name must be a string with dots as namespaces"; + $error = 'The name must be a string with dots as namespaces'; throw new InvalidArgumentException($error); } /** - * Check if a string with dots + * Check if a string with dots. * * @param $name * @return bool diff --git a/src/Notifynder/Groups/GroupRepository.php b/src/Notifynder/Groups/GroupRepository.php index 7ae9bbf..1279434 100755 --- a/src/Notifynder/Groups/GroupRepository.php +++ b/src/Notifynder/Groups/GroupRepository.php @@ -1,17 +1,16 @@ -sender], + [$notifynder, $this->sender], [$notificationsResult[0]] ); } - - return null; } /** - * Deletegate events to categories + * Deletegate events to categories. * * @param Notifynder $notifynder * @param array $data * @param array $events * @return mixed */ - public function delegate(Notifynder $notifynder, $data = [], array $events) + public function delegate(Notifynder $notifynder, $data, array $events) { foreach ($events as $category => $event) { $this->fire($notifynder, $event, $category, $data); @@ -96,7 +93,7 @@ public function delegate(Notifynder $notifynder, $data = [], array $events) /** * Tell the disptacher to send * the notification with a custom - * (extended method) + * (extended method). * * @param $customMethod * @return $this @@ -109,7 +106,7 @@ public function sendWith($customMethod) } /** - * Boot The listeners + * Boot The listeners. * * @param array $listeners */ @@ -126,7 +123,7 @@ public function boot(array $listeners) /** * Check if the fired method has some notifications - * to send + * to send. * * @param $notificationsResult * @return bool @@ -140,13 +137,13 @@ public function hasNotificationToSend($notificationsResult) } /** - * Get Event name + * Get Event name. * * @param $eventName * @return string */ protected function generateEventName($eventName) { - return static::$defaultWildcard.".".str_replace('@', '.', $eventName); + return static::$defaultWildcard.'.'.str_replace('@', '.', $eventName); } } diff --git a/src/Notifynder/Handler/NotifynderEvent.php b/src/Notifynder/Handler/NotifynderEvent.php index 79e2df9..8904301 100755 --- a/src/Notifynder/Handler/NotifynderEvent.php +++ b/src/Notifynder/Handler/NotifynderEvent.php @@ -1,15 +1,14 @@ -values)) { return $this->values[$name]; } - - return null; } /** diff --git a/src/Notifynder/Handler/NotifynderHandler.php b/src/Notifynder/Handler/NotifynderHandler.php index ee2770e..75963ea 100755 --- a/src/Notifynder/Handler/NotifynderHandler.php +++ b/src/Notifynder/Handler/NotifynderHandler.php @@ -1,24 +1,23 @@ -getNotifynderEvent(); @@ -47,13 +46,11 @@ public function handle(NotifyListener $eventListener,$notifynder = null) return $notifynder->send($builtNotifications); } } - - return null; } /** * Check if the listener exists on the class - * adding when as convention + * adding when as convention. * * ['postAdd'] whenPostAdd] * @@ -67,7 +64,7 @@ protected function listenerIsRegistered($eventName) /** * Get Event Name from the key - * it use a convention + * it use a convention. * * given user.post.add -> postAdd * given user@postAdd -> postAdd @@ -96,7 +93,7 @@ protected function getEventName($event) } /** - * Get Notifynder Instance + * Get Notifynder Instance. * * @return Notifynder */ @@ -109,7 +106,7 @@ protected function getNotifynder() /** * Check if the fired method has some notifications - * to send + * to send. * * @param $notificationsResult * @return bool diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index a0fabd4..b4e6db2 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -1,15 +1,16 @@ -where('category_id',$category); + return $query->where('category_id', $category); } - return $query->whereHas('body', function($categoryQuery) use ($category) { - $categoryQuery->where('name',$category); + return $query->whereHas('body', function ($categoryQuery) use ($category) { + $categoryQuery->where('name', $category); }); } /** * Get custom required fields from the configs * so that we can automatically bind them to the model - * fillable property + * fillable property. * * @return mixed */ @@ -199,6 +196,7 @@ public function getCustomFillableFields() if (function_exists('app') && app() instanceof Container) { return Arr::flatten(config('notifynder.additional_fields', [])); } + return []; } diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index fb833a1..55569e1 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -1,28 +1,27 @@ -items as $key => $item) { - $this->items[$key]['text'] = $parser->parse($item); } diff --git a/src/Notifynder/Notifable.php b/src/Notifynder/Notifable.php index 1b14089..334bc3b 100755 --- a/src/Notifynder/Notifable.php +++ b/src/Notifynder/Notifable.php @@ -1,21 +1,20 @@ -notifynderInstance()->entity( $this->getMorphClass() @@ -58,13 +57,13 @@ public function readLimitNotifications($numbers = 10, $order = "ASC") } /** - * Delete Limiting Notifications + * Delete Limiting Notifications. * * @param int $numbers * @param string $order * @return mixed */ - public function deleteLimitNotifications($numbers = 10, $order = "ASC") + public function deleteLimitNotifications($numbers = 10, $order = 'ASC') { return $this->notifynderInstance()->entity( $this->getMorphClass() @@ -72,9 +71,9 @@ public function deleteLimitNotifications($numbers = 10, $order = "ASC") } /** - * Delete all Notifications + * Delete all Notifications. * - * @return Bool + * @return bool */ public function deleteAllNotifications() { @@ -84,7 +83,7 @@ public function deleteAllNotifications() } /** - * Get Not Read + * Get Not Read. * * @param null $limit * @param int|null $paginate @@ -92,15 +91,15 @@ public function deleteAllNotifications() * @param Closure $filterScope * @return mixed */ - public function getNotificationsNotRead($limit = null, $paginate = null, $order = 'desc',Closure $filterScope = null) + public function getNotificationsNotRead($limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) { return $this->notifynderInstance()->entity( $this->getMorphClass() - )->getNotRead($this->id, $limit, $paginate, $order,$filterScope); + )->getNotRead($this->id, $limit, $paginate, $order, $filterScope); } /** - * Get all notifications + * Get all notifications. * * @param null $limit * @param int|null $paginate @@ -116,21 +115,21 @@ public function getNotifications($limit = null, $paginate = null, $order = 'desc } /** - * Get last notification + * Get last notification. * * @param null $category * @param Closure $filterScope * @return mixed */ - public function getLastNotification($category = null,Closure $filterScope = null) + public function getLastNotification($category = null, Closure $filterScope = null) { return $this->notifynderInstance()->entity( $this->getMorphClass() - )->getLastNotification($this->id,$category,$filterScope); + )->getLastNotification($this->id, $category, $filterScope); } /** - * Count Not read notification + * Count Not read notification. * * @param Closure $filterScope * @return mixed @@ -139,7 +138,7 @@ public function countNotificationsNotRead(Closure $filterScope = null) { return $this->notifynderInstance()->entity( $this->getMorphClass() - )->countNotRead($this->id,$filterScope); + )->countNotRead($this->id, $filterScope); } /** diff --git a/src/Notifynder/Notifications/ExtraParams.php b/src/Notifynder/Notifications/ExtraParams.php index febf90f..b40b39c 100644 --- a/src/Notifynder/Notifications/ExtraParams.php +++ b/src/Notifynder/Notifications/ExtraParams.php @@ -1,16 +1,15 @@ -isJson($extraParams)) { - $this->extraParams = json_decode($extraParams,true); - } - else { + $this->extraParams = json_decode($extraParams, true); + } else { $this->extraParams = (array) $extraParams; } } @@ -57,7 +55,7 @@ public function toArray() * * @return string */ - function __toString() + public function __toString() { $extraParams = $this->extraParams; @@ -70,7 +68,7 @@ function __toString() /** * Check if the extra param - * exists + * exists. * * @param $name * @return bool @@ -88,18 +86,17 @@ public function has($name) * @param $name string * @return mixed */ - function __get($name) + public function __get($name) { $params = $this->toArray(); - if(array_key_exists($name, $params)) { + if (array_key_exists($name, $params)) { return $params[$name]; } } - /** - * Whether a offset exists + * Whether a offset exists. * * @param mixed $offset * @return bool @@ -137,16 +134,19 @@ public function offsetUnset($offset) /** * Check if the value - * is a json string + * is a json string. * * @param $value * @return bool */ public function isJson($value) { - if (!is_string($value)) return false; + if (! is_string($value)) { + return false; + } json_decode($value); - return (json_last_error() == JSON_ERROR_NONE); + + return json_last_error() == JSON_ERROR_NONE; } -} \ No newline at end of file +} diff --git a/src/Notifynder/Notifications/NotificationManager.php b/src/Notifynder/Notifications/NotificationManager.php index 4bc9ab0..4a31760 100755 --- a/src/Notifynder/Notifications/NotificationManager.php +++ b/src/Notifynder/Notifications/NotificationManager.php @@ -1,4 +1,6 @@ -notifynderRepo->find($notification_id); if (is_null($notification)) { - $error = "Notification Not found"; + $error = 'Notification Not found'; throw new NotificationNotFoundException($error); } @@ -70,7 +69,7 @@ public function find($notification_id) /** * Make read one notification giving - * the ID of it + * the ID of it. * * @param $notification_id * @return bool|\Fenos\Notifynder\Models\Notification @@ -84,21 +83,21 @@ public function readOne($notification_id) /** * Read notifications in base the number - * Given + * Given. * * @param $to_id * @param $numbers * @param string $order * @return mixed */ - public function readLimit($to_id, $numbers, $order = "ASC") + public function readLimit($to_id, $numbers, $order = 'ASC') { return $this->notifynderRepo->readLimit($to_id, $this->entity, $numbers, $order); } /** * Read all notification of the - * given entity + * given entity. * * @param $to_id * @return Number @@ -110,10 +109,10 @@ public function readAll($to_id) /** * Delete a notification giving the id - * of it + * of it. * * @param $notification_id - * @return Bool + * @return bool */ public function delete($notification_id) { @@ -123,7 +122,7 @@ public function delete($notification_id) /** * Delete numbers of notifications equals * to the number passing as 2 parameter of - * the current user + * the current user. * * @param $entity_id * @param $number @@ -137,10 +136,10 @@ public function deleteLimit($entity_id, $number, $order = 'asc') /** * Delete all notification of a given - * Entity + * Entity. * * @param $entity_id - * @return Bool + * @return bool */ public function deleteAll($entity_id) { @@ -149,11 +148,11 @@ public function deleteAll($entity_id) /** * Delete All notifications from a - * defined category + * defined category. * * @param $category_name string * @param $expired Bool - * @return Bool + * @return bool */ public function deleteByCategory($category_name, $expired = false) { @@ -162,7 +161,7 @@ public function deleteByCategory($category_name, $expired = false) /** * Get notifications not read - * of the entity given + * of the entity given. * * @param $to_id * @param $limit @@ -179,18 +178,17 @@ public function getNotRead($to_id, $limit = null, $paginate = null, $orderDate = $filterScope ); - if(is_int(intval($paginate)) && $paginate) - { - return (new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ - 'path' => LengthAwarePaginator::resolveCurrentPath() - ])); + if (is_int(intval($paginate)) && $paginate) { + return new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ + 'path' => LengthAwarePaginator::resolveCurrentPath(), + ]); } return $notifications->parse(); } /** - * Get All notifications + * Get All notifications. * * @param $to_id * @param $limit @@ -207,11 +205,10 @@ public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'de $filterScope ); - if(is_int(intval($paginate)) && $paginate) - { - return (new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ - 'path' => LengthAwarePaginator::resolveCurrentPath() - ])); + if (is_int(intval($paginate)) && $paginate) { + return new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ + 'path' => LengthAwarePaginator::resolveCurrentPath(), + ]); } return $notifications->parse(); @@ -219,7 +216,7 @@ public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'de /** * Get last notification of the - * given entity + * given entity. * * @param $to_id * @param Closure $filterScope @@ -227,25 +224,25 @@ public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'de */ public function getLastNotification($to_id, Closure $filterScope = null) { - return $this->notifynderRepo->getLastNotification($to_id,$this->entity,$filterScope); + return $this->notifynderRepo->getLastNotification($to_id, $this->entity, $filterScope); } /** * Get last notification of the - * given entity of the specific category + * given entity of the specific category. * * @param $category * @param $to_id * @param Closure $filterScope * @return mixed */ - public function getLastNotificationByCategory($category,$to_id, Closure $filterScope = null) + public function getLastNotificationByCategory($category, $to_id, Closure $filterScope = null) { - return $this->notifynderRepo->getLastNotificationByCategory($category,$to_id,$this->entity,$filterScope); + return $this->notifynderRepo->getLastNotificationByCategory($category, $to_id, $this->entity, $filterScope); } /** - * Send single notification + * Send single notification. * * @param array $info * @return static @@ -256,7 +253,7 @@ public function sendOne(array $info) } /** - * Send multiple notifications + * Send multiple notifications. * * @param array $info * @return mixed @@ -268,7 +265,7 @@ public function sendMultiple(array $info) /** * Get number of notification - * not read + * not read. * * @param $to_id * @param Closure $filterScope diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index eeeeafa..0751725 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -1,4 +1,6 @@ -orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); - if ($limit && !$paginate) { + if ($limit && ! $paginate) { $query->limit($limit); } @@ -255,7 +253,7 @@ public function getNotRead( * Retrive all notifications, not read * in first. * You can also limit the number of - * Notifications if you don't, it will get all + * Notifications if you don't, it will get all. * * @param $to_id * @param $entity @@ -278,7 +276,7 @@ public function getAll( ->orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); - if ($limit && !$paginate) { + if ($limit && ! $paginate) { $query->limit($limit); } @@ -293,7 +291,7 @@ public function getAll( /** * get number Notifications - * not read + * not read. * * @param $to_id * @param $entity @@ -313,7 +311,7 @@ public function countNotRead($to_id, $entity, Closure $filterScope = null) /** * Get last notification of the current - * entity + * entity. * * @param $to_id * @param $entity @@ -332,7 +330,7 @@ public function getLastNotification($to_id, $entity, Closure $filterScope = null /** * Get last notification of the current - * entity of a specific category + * entity of a specific category. * * @param $category * @param $to_id @@ -353,14 +351,14 @@ public function getLastNotificationByCategory($category, $to_id, $entity, Closur } /** - * Apply scope filters + * Apply scope filters. * * @param Closure $filterScope * @param $query */ protected function applyFilter(Closure $filterScope = null, $query) { - if ( ! $filterScope) { + if (! $filterScope) { return $query; } diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php index 2c01585..e41d105 100755 --- a/src/Notifynder/Notifynder.php +++ b/src/Notifynder/Notifynder.php @@ -1,10 +1,12 @@ -send() if u pass 'sendCustom' - * it will be like $notifynder->sendCustom() + * it will be like $notifynder->sendCustom(). * * @param $customSenderName * @return $this diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index 1c4424b..78838a6 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -1,4 +1,6 @@ -notification->entity($this->entity); @@ -293,7 +292,7 @@ public function readLimit($to_id, $numbers, $order = "ASC") /** * Read all notifications of the given - * entity + * entity. * * @param $to_id * @return Number @@ -306,10 +305,10 @@ public function readAll($to_id) } /** - * Delete a single notification + * Delete a single notification. * * @param $notification_id - * @return Bool + * @return bool */ public function delete($notification_id) { @@ -318,14 +317,14 @@ public function delete($notification_id) /** * Delete number of notifications - * secified of the given entity + * secified of the given entity. * * @param $to_id * @param $number * @param string $order * @return mixed */ - public function deleteLimit($to_id, $number, $order = "ASC") + public function deleteLimit($to_id, $number, $order = 'ASC') { $notifications = $this->notification->entity($this->entity); @@ -334,10 +333,10 @@ public function deleteLimit($to_id, $number, $order = "ASC") /** * Delete all notifications - * of the the given entity + * of the the given entity. * * @param $to_id - * @return Bool + * @return bool */ public function deleteAll($to_id) { @@ -348,11 +347,11 @@ public function deleteAll($to_id) /** * Delete All notifications from a - * defined category + * defined category. * * @param $category_name string * @param $expired Bool - * @return Bool + * @return bool */ public function deleteByCategory($category_name, $expired = false) { @@ -361,7 +360,7 @@ public function deleteByCategory($category_name, $expired = false) /** * Get Notifications not read - * of the given entity + * of the given entity. * * @param $to_id * @param null $limit @@ -370,7 +369,7 @@ public function deleteByCategory($category_name, $expired = false) * @param Closure $filterScope * @return mixed */ - public function getNotRead($to_id, $limit = null, $paginate = null, $order = "desc", Closure $filterScope = null) + public function getNotRead($to_id, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); @@ -379,7 +378,7 @@ public function getNotRead($to_id, $limit = null, $paginate = null, $order = "de /** * Get all notifications of the - * given entity + * given entity. * * @param $to_id * @param null $limit @@ -388,30 +387,30 @@ public function getNotRead($to_id, $limit = null, $paginate = null, $order = "de * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $limit = null, $paginate = null, $order = "desc", Closure $filterScope = null) + public function getAll($to_id, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); - return $notifications->getAll($to_id, $limit, $paginate,$order, $filterScope); + return $notifications->getAll($to_id, $limit, $paginate, $order, $filterScope); } /** * Get number of notification not read - * of the given entity + * of the given entity. * * @param $to_id * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id,Closure $filterScope = null) + public function countNotRead($to_id, Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); - return $notifications->countNotRead($to_id,$filterScope); + return $notifications->countNotRead($to_id, $filterScope); } /** - * Find Notification by ID + * Find Notification by ID. * * @param $notification_id * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static @@ -424,27 +423,27 @@ public function findNotificationById($notification_id) /** * Get last notification of the given * entity, second parameter can filter by - * category + * category. * * @param $to_id * @param null $category * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id,$category = null,Closure $filterScope = null) + public function getLastNotification($to_id, $category = null, Closure $filterScope = null) { $notification = $this->notification->entity($this->entity); - if ( is_null($category)) { - return $notification->getLastNotification($to_id,$filterScope); + if (is_null($category)) { + return $notification->getLastNotification($to_id, $filterScope); } - return $notification->getLastNotificationByCategory($category,$to_id,$filterScope); + return $notification->getLastNotificationByCategory($category, $to_id, $filterScope); } /** * Add category to a group - * giving the names of them + * giving the names of them. * * @param $gorup_name * @param $category_name @@ -457,7 +456,7 @@ public function addCategoryToGroupByName($gorup_name, $category_name) /** * Add category to a group - * giving the ids of them + * giving the ids of them. * * @param $gorup_id * @param $category_id @@ -471,7 +470,7 @@ public function addCategoryToGroupById($gorup_id, $category_id) /** * Add categories to a group having as first parameter * the name of the group, and others as name - * categories + * categories. * * @return mixed */ @@ -482,7 +481,7 @@ public function addCategoriesToGroup() /** * Fire method for fire listeners - * of logic + * of logic. * * @param string $key * @param string $category_name @@ -496,7 +495,7 @@ public function fire($key, $category_name, $values = []) } /** - * Associate events to categories + * Associate events to categories. * * @param $data * @param array $delegation @@ -508,7 +507,7 @@ public function delegate(array $delegation, $data = []) } /** - * Boot Listeners + * Boot Listeners. * * @param array $listeners */ @@ -518,7 +517,7 @@ public function bootListeners(array $listeners) } /** - * Get instance of the notifynder builder + * Get instance of the notifynder builder. * * @return NotifynderBuilder */ @@ -528,7 +527,7 @@ public function builder() } /** - * Extend a custom sender method + * Extend a custom sender method. * * @param $name * @param callable $registrar @@ -537,7 +536,7 @@ public function builder() public function extend($name, $registrar) { if (! starts_with($name, 'send')) { - $error = "The sender method must start with [send]"; + $error = 'The sender method must start with [send]'; throw new InvalidArgumentException($error); } @@ -547,7 +546,7 @@ public function extend($name, $registrar) } /** - * Check if the category is eager Loaded + * Check if the category is eager Loaded. * * @param $name * @return bool @@ -558,7 +557,7 @@ protected function isLazyLoaded($name) } /** - * Return the Id of the category + * Return the Id of the category. * * @return mixed */ @@ -569,7 +568,7 @@ public function id() /** * Push a category in the categoriesContainer - * property + * property. * * @param $name * @param array $categoriesContainer @@ -580,7 +579,7 @@ protected function setCategoriesContainer($name, $categoriesContainer) } /** - * Get the categoriesContainer property + * Get the categoriesContainer property. * * @param $name * @return array @@ -593,7 +592,7 @@ public function getCategoriesContainer($name) /** * Define which method * the event dispatcher has - * to send the notifications + * to send the notifications. * * @param $customSenderName * @return $this @@ -606,7 +605,7 @@ public function dipatchWith($customSenderName) } /** - * Call the custom sender method + * Call the custom sender method. * * @param $name * @param $arguments @@ -615,11 +614,11 @@ public function dipatchWith($customSenderName) public function __call($name, $arguments) { if (starts_with($name, 'send')) { - $arguments = (isset($arguments[0])) ? $arguments[0] : $this->toArray(); - $notificationsSent = $this->notifynderSender->customSender($name,$arguments); + $notificationsSent = $this->notifynderSender->customSender($name, $arguments); $this->refresh(); + return $notificationsSent; } @@ -629,24 +628,24 @@ public function __call($name, $arguments) /** * Set builder properties - * When setting dynamic properties + * When setting dynamic properties. * * @param $name * @param $value */ - function __set($name, $value) + public function __set($name, $value) { - $this->offsetSet($name,$value); + $this->offsetSet($name, $value); } /** * Get property from the - * builder + * builder. * * @param $name * @return mixed */ - function __get($name) + public function __get($name) { return $this->offsetGet($name); } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index e966239..ff2bb0a 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -1,4 +1,6 @@ -app->resolving(Notification::class, function (Notification $object, $app) { $fillable = $app['config']->get('notifynder.additional_fields.fillable', []); - $object->fillable(array_merge($object->getFillable(),$fillable)); + $object->fillable(array_merge($object->getFillable(), $fillable)); }); // Default store notification @@ -135,7 +136,7 @@ protected function notifications() } /** - * Bind Translator + * Bind Translator. */ protected function translator() { @@ -154,7 +155,7 @@ protected function translator() } /** - * Bind Senders + * Bind Senders. */ protected function senders() { @@ -175,7 +176,7 @@ protected function senders() } /** - * Bind Dispatcher + * Bind Dispatcher. */ protected function events() { @@ -187,7 +188,7 @@ protected function events() } /** - * Bind Groups + * Bind Groups. */ protected function groups() { @@ -213,7 +214,7 @@ protected function groups() } /** - * Bind Builder + * Bind Builder. */ protected function builder() { @@ -229,7 +230,7 @@ protected function builder() } /** - * Contracts of notifynder + * Contracts of notifynder. */ protected function contracts() { @@ -255,7 +256,7 @@ protected function contracts() } /** - * Publish config files + * Publish config files. */ protected function config() { @@ -267,34 +268,34 @@ protected function config() // Set use strict_extra config option, // you can toggle it in the configuraiton file - $strictParam = $this->app['config']->get('notifynder.strict_extra',false); + $strictParam = $this->app['config']->get('notifynder.strict_extra', false); NotifynderParser::setStrictExtra($strictParam); } /** - * Publish migration files + * Publish migration files. */ protected function migration() { - if (!class_exists('NotificationCategories')) { + if (! class_exists('NotificationCategories')) { $this->publishMigration('2014_02_10_145728_notification_categories'); } - if (!class_exists('CreateNotificationGroupsTable')) { + if (! class_exists('CreateNotificationGroupsTable')) { $this->publishMigration('2014_08_01_210813_create_notification_groups_table'); } - if (!class_exists('CreateNotificationCategoryNotificationGroupTable')) { + if (! class_exists('CreateNotificationCategoryNotificationGroupTable')) { $this->publishMigration('2014_08_01_211045_create_notification_category_notification_group_table'); } - if (!class_exists('CreateNotificationsTable')) { + if (! class_exists('CreateNotificationsTable')) { $this->publishMigration('2015_05_05_212549_create_notifications_table'); } - if (!class_exists('AddExpireTimeColumnToNotificationTable')) { + if (! class_exists('AddExpireTimeColumnToNotificationTable')) { $this->publishMigration('2015_06_06_211555_add_expire_time_column_to_notification_table'); } - if (!class_exists('ChangeTypeToExtraInNotificationsTable')) { + if (! class_exists('ChangeTypeToExtraInNotificationsTable')) { $this->publishMigration('2015_06_06_211555_change_type_to_extra_in_notifications_table'); } - if (!class_exists('AlterCategoryNameToUnique')) { + if (! class_exists('AlterCategoryNameToUnique')) { $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique'); } } @@ -317,7 +318,7 @@ protected function publishMigration($filename) */ protected function migrationFilepath($filename) { - if(function_exists('database_path')) { + if (function_exists('database_path')) { return database_path('/migrations/'.$filename); } else { return base_path('/database/migrations/'.$filename); @@ -325,7 +326,7 @@ protected function migrationFilepath($filename) } /** - * Register Artisan commands + * Register Artisan commands. */ protected function artisan() { diff --git a/src/Notifynder/Parsers/ArtisanOptionsParser.php b/src/Notifynder/Parsers/ArtisanOptionsParser.php index c5a4d06..5827324 100755 --- a/src/Notifynder/Parsers/ArtisanOptionsParser.php +++ b/src/Notifynder/Parsers/ArtisanOptionsParser.php @@ -1,16 +1,15 @@ -getValues($body); if (count($specialValues) > 0) { - $specialValues = array_filter($specialValues, function($value) { - return (starts_with($value, 'extra.') || starts_with($value, 'to.') || starts_with($value, 'from.')); + $specialValues = array_filter($specialValues, function ($value) { + return starts_with($value, 'extra.') || starts_with($value, 'to.') || starts_with($value, 'from.'); }); foreach ($specialValues as $replacer) { $replace = $this->mixedGet($item, $replacer); - if(empty($replace) && static::$strictMode) { + if (empty($replace) && static::$strictMode) { $error = "the following [$replacer] param required from your category it's missing. Did you forget to store it?"; throw new ExtraParamsException($error); } @@ -61,7 +60,7 @@ public function parse($item) * Set strict mode. * if it's enabled then will throws exceptions * when extra params will not be parsed correctly - * will be handy in development + * will be handy in development. * * @param bool|true $set */ @@ -72,7 +71,7 @@ public static function setStrictExtra($set = true) /** * Get the values between {} - * and return an array of it + * and return an array of it. * * @param $body * @return mixed @@ -87,7 +86,7 @@ protected function getValues($body) /** * Trying to transform extra in from few datatypes - * to array type + * to array type. * * @param $extra * @return array|mixed @@ -95,20 +94,18 @@ protected function getValues($body) protected function extraToArray($extra) { if ($this->isJson($extra)) { - $extra = json_decode($extra, true); - return $extra; - } else if ($extra instanceof ExtraParams) { + return $extra; + } elseif ($extra instanceof ExtraParams) { $extra = $extra->toArray(); + return $extra; } - - return null; } /** - * Replace body of the category + * Replace body of the category. * * @param $body * @param $replacer @@ -123,25 +120,24 @@ protected function replaceBody($body, $valueMatch, $replacer) } /** - * Check if is a json string + * Check if is a json string. * * @param $value * @return bool */ protected function isJson($value) { - if ( ! is_string($value)) { + if (! is_string($value)) { return false; } json_decode($value); - return (json_last_error() == JSON_ERROR_NONE); + return json_last_error() == JSON_ERROR_NONE; } - /** - * Get a value by dot-key of an array, object or mix of both + * Get a value by dot-key of an array, object or mix of both. * * @param array|object $object * @param string $key @@ -157,9 +153,9 @@ protected function mixedGet($object, $key, $default = null) foreach (explode('.', $key) as $segment) { if (is_object($object) && isset($object->{$segment})) { $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { + } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { + } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { $object = $object->getAttribute($segment); } elseif (is_array($object) && array_key_exists($segment, $object)) { $object = array_get($object, $segment, $default); @@ -170,4 +166,4 @@ protected function mixedGet($object, $key, $default = null) return $object; } -} \ No newline at end of file +} diff --git a/src/Notifynder/Senders/SendGroup.php b/src/Notifynder/Senders/SendGroup.php index d0ba58c..fca9baa 100755 --- a/src/Notifynder/Senders/SendGroup.php +++ b/src/Notifynder/Senders/SendGroup.php @@ -1,4 +1,6 @@ -infoNotification)) { - $error = "Category not found please provide one, - you can not store a notification without category id"; + $error = 'Category not found please provide one, + you can not store a notification without category id'; throw new CategoryNotFoundException($error); } diff --git a/src/Notifynder/Senders/SenderFactory.php b/src/Notifynder/Senders/SenderFactory.php index 4cb5b86..cea9329 100755 --- a/src/Notifynder/Senders/SenderFactory.php +++ b/src/Notifynder/Senders/SenderFactory.php @@ -1,6 +1,8 @@ -toArray(); } // if the array is multidimesional // it means that we want to send // multiple notifications - if ($this->isMultiArray($infoNotifications)) - { + if ($this->isMultiArray($infoNotifications)) { return $this->sendMultiple($infoNotifications); - } - else - { + } else { return $this->sendSingle($infoNotifications, $category); } } /** - * Send Single Notification Sender + * Send Single Notification Sender. * * @param array $infoNotifications * @param $category @@ -79,7 +74,7 @@ public function sendSingle(array $infoNotifications, $category) } /** - * Send Multiple Notification Sender + * Send Multiple Notification Sender. * * @param array $infoNotifications * @return SendMultiple @@ -90,7 +85,7 @@ public function sendMultiple(array $infoNotifications) } /** - * Get the the send group instance + * Get the the send group instance. * * @param string $group_name * @param array | \Closure $info @@ -108,7 +103,7 @@ public function sendGroup($group_name, array $info) /** * Check if the array passed is - * multidimensional + * multidimensional. * * @param $arr * @return bool diff --git a/src/Notifynder/Senders/SenderManager.php b/src/Notifynder/Senders/SenderManager.php index 765e13b..f73ed7a 100755 --- a/src/Notifynder/Senders/SenderManager.php +++ b/src/Notifynder/Senders/SenderManager.php @@ -1,4 +1,6 @@ -senders)) { @@ -155,12 +154,11 @@ public function customSender($customMethod,$notification) // I invoke the closue expecting an Instance of a custorm // Sender - $invoker = call_user_func_array($extendedSender, [$notification,$this->container]); + $invoker = call_user_func_array($extendedSender, [$notification, $this->container]); // If the invoker is a custom sender // then I invoke it passing the sender class if ($invoker instanceof Sender) { - return $invoker->send($this); } @@ -168,12 +166,11 @@ public function customSender($customMethod,$notification) // way of storing notifications then // i'll pass the storenotification contract if ($invoker instanceof DefaultSender) { - return $invoker->send($this->storeNotification); } } - $error = "The extention must be an instance of Closure"; + $error = 'The extention must be an instance of Closure'; throw new LogicException($error); } @@ -183,20 +180,20 @@ public function customSender($customMethod,$notification) /** * When calling a not existing method - * try to resolve with an exteded + * try to resolve with an exteded. * * @param $name * @param $arguments * @return mixed */ - function __call($name, $arguments) + public function __call($name, $arguments) { if (isset($arguments[0])) { - return $this->customSender($name,$arguments[0]); + return $this->customSender($name, $arguments[0]); } - $error = "No argument passed to the custom sender, - please provide notifications array"; + $error = 'No argument passed to the custom sender, + please provide notifications array'; throw new BadMethodCallException($error); } } diff --git a/src/Notifynder/Translator/Compiler.php b/src/Notifynder/Translator/Compiler.php index e4a2084..82ecf83 100755 --- a/src/Notifynder/Translator/Compiler.php +++ b/src/Notifynder/Translator/Compiler.php @@ -1,19 +1,18 @@ - 'text to {parse value} translate' * ] * ] - * - * @package Fenos\Notifynder\Translator */ class TranslatorManager implements NotifynderTranslator { - /** * @var Compiler */ @@ -47,7 +46,7 @@ public function __construct(Compiler $compiler, Repository $config) } /** - * Translate the given category + * Translate the given category. * * @param $language * @param $nameCategory @@ -63,12 +62,12 @@ public function translate($language, $nameCategory) return $translations[$nameCategory]; } - $error = "Translation not found"; + $error = 'Translation not found'; throw new NotificationTranslationNotFoundException($error); } /** - * Get selected language of tranlsations + * Get selected language of tranlsations. * * @param $language * @return mixed @@ -82,12 +81,12 @@ public function getLanguage($language) return $translations[$language]; } - $error = "Language Not Found"; + $error = 'Language Not Found'; throw new NotificationLanguageNotFoundException($error); } /** - * Get translations + * Get translations. * * @return array|mixed */ @@ -114,7 +113,7 @@ public function getTranslations() /** * Get the translations from the * array of the config file and it - * will cache them + * will cache them. * * @return array */ diff --git a/src/config/notifynder.php b/src/config/notifynder.php index 3d14117..cf70da4 100755 --- a/src/config/notifynder.php +++ b/src/config/notifynder.php @@ -8,20 +8,20 @@ return [ - /** + /* * If you have a different user model * please specific it here, this option is not * considerate if using notifynder as polymorphic */ 'model' => 'App\User', - /** + /* * Do you want have notifynder that work polymorphically? * just swap the value to true and you will able to use it! */ 'polymorphic' => false, - /** + /* * If you need to extend the model class of * Notifynder you just need to change this line * With the path / NameSpace of your model and extend it @@ -29,7 +29,7 @@ */ 'notification_model' => 'Fenos\Notifynder\Models\Notification', - /** + /* * Coordinating a lots notifications that require extra params * might cause to forget and not insert the {extra.*} value needed. * This flag allow you to cause an exception to be thrown if you miss @@ -39,7 +39,7 @@ */ 'strict_extra' => false, - /** + /* * If you wish to have the translations in a specific file * just require the file on the following option. * @@ -51,7 +51,7 @@ ], - /** + /* * If you have added your own fields to the Notification Model * you can add them to the arrays below. * diff --git a/src/migrations/2014_02_10_145728_notification_categories.php b/src/migrations/2014_02_10_145728_notification_categories.php index 092c54f..b58b7cd 100755 --- a/src/migrations/2014_02_10_145728_notification_categories.php +++ b/src/migrations/2014_02_10_145728_notification_categories.php @@ -5,7 +5,6 @@ class NotificationCategories extends Migration { - /** * Run the migrations. * diff --git a/src/migrations/2014_08_01_210813_create_notification_groups_table.php b/src/migrations/2014_08_01_210813_create_notification_groups_table.php index 47ea82e..d048a59 100755 --- a/src/migrations/2014_08_01_210813_create_notification_groups_table.php +++ b/src/migrations/2014_08_01_210813_create_notification_groups_table.php @@ -5,7 +5,6 @@ class CreateNotificationGroupsTable extends Migration { - /** * Run the migrations. * diff --git a/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php b/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php index cd0ebb5..7b243f7 100755 --- a/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php +++ b/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php @@ -5,7 +5,6 @@ class CreateNotificationCategoryNotificationGroupTable extends Migration { - /** * Run the migrations. * diff --git a/src/migrations/2015_05_05_212549_create_notifications_table.php b/src/migrations/2015_05_05_212549_create_notifications_table.php index d9a4339..90c35c9 100755 --- a/src/migrations/2015_05_05_212549_create_notifications_table.php +++ b/src/migrations/2015_05_05_212549_create_notifications_table.php @@ -5,7 +5,6 @@ class CreateNotificationsTable extends Migration { - /** * Run the migrations. * diff --git a/src/migrations/2015_06_06_211555_add_expire_time_column_to_notification_table.php b/src/migrations/2015_06_06_211555_add_expire_time_column_to_notification_table.php index 611073c..3382315 100755 --- a/src/migrations/2015_06_06_211555_add_expire_time_column_to_notification_table.php +++ b/src/migrations/2015_06_06_211555_add_expire_time_column_to_notification_table.php @@ -4,7 +4,6 @@ class AddExpireTimeColumnToNotificationTable extends Migration { - /** * Run the migrations. * diff --git a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php index c41d245..850a054 100755 --- a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php +++ b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php @@ -4,7 +4,6 @@ class ChangeTypeToExtraInNotificationsTable extends Migration { - /** * Run the migrations. * @@ -15,12 +14,9 @@ public function up() Schema::table('notifications', function ($table) { $driver = Config::get('database.driver'); - if ($driver === 'mysql' || $driver === 'sqlite') - { + if ($driver === 'mysql' || $driver === 'sqlite') { DB::statement('ALTER TABLE notifications MODIFY COLUMN extra json'); - } - elseif ($driver === 'pgsql') - { + } elseif ($driver === 'pgsql') { DB::statement('ALTER TABLE notifications ALTER COLUMN extra TYPE json USING code::string'); } }); @@ -37,12 +33,9 @@ public function down() $driver = Config::get('database.driver'); - if ($driver === 'mysql' || $driver === 'sqlite') - { + if ($driver === 'mysql' || $driver === 'sqlite') { DB::statement('ALTER TABLE notifications MODIFY COLUMN extra STRING(255)'); - } - elseif ($driver === 'pgsql') - { + } elseif ($driver === 'pgsql') { DB::statement('ALTER TABLE notifications ALTER COLUMN extra TYPE string USING code::json'); } }); diff --git a/src/migrations/2015_06_07_211555_alter_category_name_to_unique.php b/src/migrations/2015_06_07_211555_alter_category_name_to_unique.php index c1ddd18..cfbc7a9 100755 --- a/src/migrations/2015_06_07_211555_alter_category_name_to_unique.php +++ b/src/migrations/2015_06_07_211555_alter_category_name_to_unique.php @@ -4,7 +4,6 @@ class AlterCategoryNameToUnique extends Migration { - /** * Run the migrations. * diff --git a/src/migrations/2016_04_19_200827_make_url_nullable.php b/src/migrations/2016_04_19_200827_make_url_nullable.php index 642c01f..58340dc 100644 --- a/src/migrations/2016_04_19_200827_make_url_nullable.php +++ b/src/migrations/2016_04_19_200827_make_url_nullable.php @@ -5,7 +5,6 @@ class MakeUrlNullable extends Migration { - /** * Run the migrations. * diff --git a/tests/TestCaseDB.php b/tests/TestCaseDB.php index c8dbb2a..e106474 100755 --- a/tests/TestCaseDB.php +++ b/tests/TestCaseDB.php @@ -3,10 +3,10 @@ use Orchestra\Testbench\TestCase; /** - * Class TestCaseDB + * Class TestCaseDB. */ -abstract class TestCaseDB extends TestCase { - +abstract class TestCaseDB extends TestCase +{ /** * @param \Illuminate\Foundation\Application $app * @return array @@ -29,12 +29,11 @@ public function setUp() app('db')->beginTransaction(); $this->migrate($artisan); - $this->migrate($artisan,'/../../../../tests/migrations'); + $this->migrate($artisan, '/../../../../tests/migrations'); // Set up the User Test Model - app('config')->set('notifynder.notification_model','Fenos\Notifynder\Models\Notification'); - app('config')->set('notifynder.model','Fenos\Tests\Models\User'); - + app('config')->set('notifynder.notification_model', 'Fenos\Notifynder\Models\Notification'); + app('config')->set('notifynder.model', 'Fenos\Tests\Models\User'); } /** @@ -46,11 +45,11 @@ public function setUp() protected function getEnvironmentSetUp($app) { $app['config']->set('database.default', 'testbench'); - $app['config']->set('database.connections.testbench', array( + $app['config']->set('database.connections.testbench', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', - )); + ]); } /** @@ -73,16 +72,16 @@ protected function getApplicationTimezone($app) } /** - * Migrate the migrations files + * Migrate the migrations files. * * @param $artisan * @param string $path */ - private function migrate($artisan,$path = '/../../../../src/migrations') + private function migrate($artisan, $path = '/../../../../src/migrations') { $artisan->call('migrate', [ '--database' => 'testbench', - '--path' => $path + '--path' => $path, ]); } -} \ No newline at end of file +} diff --git a/tests/factories/factories.php b/tests/factories/factories.php index acf1bf6..33b2583 100755 --- a/tests/factories/factories.php +++ b/tests/factories/factories.php @@ -1,19 +1,18 @@ $faker->name, - 'text' => 'test notification' + 'text' => 'test notification', ]); - -$factory('Fenos\Tests\Models\User',[ +$factory('Fenos\Tests\Models\User', [ 'name' => $faker->name, - 'surname' => $faker->lastName + 'surname' => $faker->lastName, ]); -$factory('Fenos\Notifynder\Models\Notification',[ +$factory('Fenos\Notifynder\Models\Notification', [ 'from_id' => 'factory:Fenos\Tests\Models\User', 'from_type' => 'Fenos\Tests\Models\User', @@ -28,6 +27,6 @@ 'updated_at' => $faker->dateTime, ]); -$factory('Fenos\Notifynder\Models\NotificationGroup',[ +$factory('Fenos\Notifynder\Models\NotificationGroup', [ 'name' => $faker->name, -]); \ No newline at end of file +]); diff --git a/tests/integration/CreateModels.php b/tests/integration/CreateModels.php index e2eb588..e6c9a3e 100755 --- a/tests/integration/CreateModels.php +++ b/tests/integration/CreateModels.php @@ -3,43 +3,43 @@ use Fenos\Notifynder\Models\Notification; use Laracasts\TestDummy\Factory; -trait CreateModels { - +trait CreateModels +{ /** - * Create Category + * Create Category. * * @param array $data * @return mixed */ protected function createCategory(array $data = []) { - return Factory::create('Fenos\Notifynder\Models\NotificationCategory',$data); + return Factory::create('Fenos\Notifynder\Models\NotificationCategory', $data); } /** - * Create Group + * Create Group. * * @param array $data * @return mixed */ protected function createGroup(array $data = []) { - return Factory::create('Fenos\Notifynder\Models\NotificationGroup',$data); + return Factory::create('Fenos\Notifynder\Models\NotificationGroup', $data); } /** - * Shortcut to create a new notification + * Shortcut to create a new notification. * * @param array $data * @return mixed */ protected function createNotification(array $data = []) { - return Factory::create(Notification::class,$data); + return Factory::create(Notification::class, $data); } /** - * Shortcut Multi notifications + * Shortcut Multi notifications. * * @param array $data * @return mixed @@ -49,11 +49,11 @@ protected function createMultipleNotifications(array $data = []) $to_entity = [ 'to_id' => $this->to['id'], 'to_type' => $this->to['type'], - 'read' => 0 + 'read' => 0, ]; return Factory::times($this->multiNotificationsNumber) - ->create(Notification::class,array_merge($to_entity,$data)); + ->create(Notification::class, array_merge($to_entity, $data)); } /** @@ -62,6 +62,6 @@ protected function createMultipleNotifications(array $data = []) */ protected function createUser(array $data = []) { - return Factory::create('Fenos\Tests\Models\User',$data); + return Factory::create('Fenos\Tests\Models\User', $data); } -} \ No newline at end of file +} diff --git a/tests/integration/CustomSender.php b/tests/integration/CustomSender.php index 21eaaa3..60802df 100755 --- a/tests/integration/CustomSender.php +++ b/tests/integration/CustomSender.php @@ -2,10 +2,9 @@ use Fenos\Notifynder\Contracts\NotifynderSender; use Fenos\Notifynder\Contracts\Sender; -use Fenos\Notifynder\Contracts\StoreNotification; /** - * Class CustomSender + * Class CustomSender. */ class CustomDefaultSender implements Sender { @@ -23,21 +22,21 @@ class CustomDefaultSender implements Sender * @param array $notifications * @param \Fenos\Notifynder\NotifynderManager $notifynder */ - function __construct(array $notifications,\Fenos\Notifynder\NotifynderManager $notifynder) + public function __construct(array $notifications, \Fenos\Notifynder\NotifynderManager $notifynder) { $this->notifications = $notifications; $this->notifynder = $notifynder; } /** - * Send notification + * Send notification. * * @param NotifynderSender $sender * @return mixed */ public function send(NotifynderSender $sender) { -// dd($storeNotification); + // dd($storeNotification); return $sender->send($this->notifications); } -} \ No newline at end of file +} diff --git a/tests/integration/Handler/NotifyEvent.php b/tests/integration/Handler/NotifyEvent.php index d35abf3..fb32504 100755 --- a/tests/integration/Handler/NotifyEvent.php +++ b/tests/integration/Handler/NotifyEvent.php @@ -4,10 +4,10 @@ use Fenos\Notifynder\Handler\NotifynderEvent; /** - * Class NotifyEvent + * Class NotifyEvent. */ -class NotifyEvent implements NotifyListener { - +class NotifyEvent implements NotifyListener +{ /** * @var NotifynderEvent */ @@ -16,7 +16,7 @@ class NotifyEvent implements NotifyListener { /** * @param $notifynderEvent */ - function __construct(NotifynderEvent $notifynderEvent) + public function __construct(NotifynderEvent $notifynderEvent) { $this->notifynderEvent = $notifynderEvent; } @@ -28,4 +28,4 @@ public function getNotifynderEvent() { return $this->notifynderEvent; } -} \ No newline at end of file +} diff --git a/tests/integration/Handler/NotifynderHandlerTest.php b/tests/integration/Handler/NotifynderHandlerTest.php index 155b3e9..cafaf29 100755 --- a/tests/integration/Handler/NotifynderHandlerTest.php +++ b/tests/integration/Handler/NotifynderHandlerTest.php @@ -1,6 +1,6 @@ 'NotifyUserTest' + 'notify.*' => 'NotifyUserTest', ]; /** - * User to + * User to. * * @var User */ @@ -46,7 +46,7 @@ class NotifynderHandlerTest extends TestCaseDB { protected $laravelDispatcher; /** - * Listen test listeners + * Listen test listeners. */ public function setUp() { @@ -64,61 +64,59 @@ public function setUp() // Create Category $this->createCategory([ - 'name' => 'activation' + 'name' => 'activation', ]); $this->createCategory([ - 'name' => 'confirmation' + 'name' => 'confirmation', ]); } /** @test */ - function it_fire_an_event_sending_a_specific_notification_from_the_handler() + public function it_fire_an_event_sending_a_specific_notification_from_the_handler() { - $this->dispatcher->fire('notify@userActivated','activation'); + $this->dispatcher->fire('notify@userActivated', 'activation'); $notification = \Fenos\Notifynder\Models\Notification::all(); - $this->assertCount(1,$notification); + $this->assertCount(1, $notification); } /** @test */ - function it_fire_an_event_sending_multiple_notifications() + public function it_fire_an_event_sending_multiple_notifications() { - $this->dispatcher->fire('notify@userMultiple','activation'); + $this->dispatcher->fire('notify@userMultiple', 'activation'); $notification = \Fenos\Notifynder\Models\Notification::all(); - $this->assertCount(2,$notification); + $this->assertCount(2, $notification); } /** @test */ - function it_delete_2_notification_to_be_sent_trought_the_handler() + public function it_delete_2_notification_to_be_sent_trought_the_handler() { $this->dispatcher->delegate([ 'activation' => 'notify@userActivated', - 'confirmation' => 'notify@userMultiple' + 'confirmation' => 'notify@userMultiple', ]); $notification = \Fenos\Notifynder\Models\Notification::all(); - $this->assertCount(3,$notification); + $this->assertCount(3, $notification); } /** @test */ - function it_trigger_an_handler_using_native_laravel_dispatcher() + public function it_trigger_an_handler_using_native_laravel_dispatcher() { $testListener = [ NotifyEvent::class => [ - NotifyUserTest::class - ] + NotifyUserTest::class, + ], ]; // Listen for events as the laravel way - foreach ($testListener as $event => $listeners) - { - foreach ($listeners as $listener) - { + foreach ($testListener as $event => $listeners) { + foreach ($listeners as $listener) { $this->laravelDispatcher->listen($event, $listener); } } @@ -127,7 +125,7 @@ function it_trigger_an_handler_using_native_laravel_dispatcher() new NotifyEvent(new NotifynderEvent('userActivated')) ); - $this->assertEquals('hello',$notification[0]->url); + $this->assertEquals('hello', $notification[0]->url); } } @@ -139,12 +137,12 @@ function it_trigger_an_handler_using_native_laravel_dispatcher() --------------------------------------------------------------------------*/ /** - * Class NotifyUserTest + * Class NotifyUserTest. */ -class NotifyUserTest extends NotifynderHandler { - +class NotifyUserTest extends NotifynderHandler +{ /** - * Test trigger one notification + * Test trigger one notification. * * @param NotifynderEvent $event * @param NotifynderManager $notifynder @@ -162,7 +160,7 @@ public function userActivated(NotifynderEvent $event, NotifynderManager $notifyn /** * Test send multiple notifications from - * the handler + * the handler. * * @param NotifynderEvent $event * @param NotifynderManager $notifynder @@ -171,9 +169,9 @@ public function userActivated(NotifynderEvent $event, NotifynderManager $notifyn public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynder) { // Retrieve users - $users = [1,2]; + $users = [1, 2]; - return $notifynder->builder()->loop($users,function(NotifynderBuilder $builder,$value,$key) { + return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { return $builder->category('activation') ->url('hello') @@ -181,5 +179,4 @@ public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynd ->to($value); }); } - -} \ No newline at end of file +} diff --git a/tests/integration/Notifable/NotifableTest.php b/tests/integration/Notifable/NotifableTest.php index a87bea6..231d8b3 100755 --- a/tests/integration/Notifable/NotifableTest.php +++ b/tests/integration/Notifable/NotifableTest.php @@ -5,10 +5,10 @@ use Laracasts\TestDummy\Factory; /** - * Class NotificationTest + * Class NotificationTest. */ -class NotifableTraitTest extends TestCaseDB { - +class NotifableTraitTest extends TestCaseDB +{ use CreateModels; /** @@ -21,7 +21,7 @@ class NotifableTraitTest extends TestCaseDB { */ protected $to = [ 'id' => 1, - 'type' => 'Fenos\Tests\Models\User' + 'type' => 'Fenos\Tests\Models\User', ]; /** @@ -35,7 +35,7 @@ class NotifableTraitTest extends TestCaseDB { protected $user; /** - * Set Up Test + * Set Up Test. */ public function setUp() { @@ -47,84 +47,84 @@ public function setUp() /** * @test */ - public function it_count_notification_not_read() { - + public function it_count_notification_not_read() + { $this->createMultipleNotifications(['read' => 1]); $count = $this->user->countNotificationsNotRead(); - $this->assertEquals(0,$count); + $this->assertEquals(0, $count); } /** - * It read all notifications + * It read all notifications. * * @method readLimitNotifications * @test */ - function it_real_all_notifications() + public function it_real_all_notifications() { $this->createMultipleNotifications(); $read = $this->user->readAllNotifications(); - $this->assertEquals(10,$read); + $this->assertEquals(10, $read); } /** * It read limiting amount the of - * notifications + * notifications. * * @method readLimitNotifications * @test */ - function it_read_a_limit_of_notifications() + public function it_read_a_limit_of_notifications() { $this->createMultipleNotifications(); $read = $this->user->readLimitNotifications(6); - $this->assertEquals(6,$read); + $this->assertEquals(6, $read); } /** * It delete limiting the amount of - * notifications + * notifications. * * @method deleteLimitNotifications * @test */ - function it_delete_limit_notifications() + public function it_delete_limit_notifications() { $this->createMultipleNotifications(); $deleted = $this->user->deleteLimitNotifications(4); - $this->assertEquals(4,$deleted); + $this->assertEquals(4, $deleted); } /** - * It delete all notifications + * It delete all notifications. * * @method deleteAllNotifications * @test */ - function it_delete_all_notifications() + public function it_delete_all_notifications() { $this->createMultipleNotifications(); $deleted = $this->user->deleteAllNotifications(); - $this->assertEquals($this->multiNotificationsNumber,$deleted); + $this->assertEquals($this->multiNotificationsNumber, $deleted); } /** - * Get notifications unread + * Get notifications unread. * * @method * @test */ - function it_get_notifications_not_read() + public function it_get_notifications_not_read() { // 20 total $this->createMultipleNotifications(); @@ -133,38 +133,38 @@ function it_get_notifications_not_read() $getNotificationNotRead = $this->user->getNotificationsNotRead(); - $this->assertCount(10,$getNotificationNotRead); + $this->assertCount(10, $getNotificationNotRead); } /** - * Get all notifications + * Get all notifications. * * @method getNotifications * @test */ - function it_get_all_notification_of_the_current_user() + public function it_get_all_notification_of_the_current_user() { $this->createMultipleNotifications(); $notifications = $this->user->getNotifications(); - $this->assertCount(10,$notifications); + $this->assertCount(10, $notifications); } /** - * get the last notification + * get the last notification. * * @method getLastNotification * @test */ - function it_get_last_notification() + public function it_get_last_notification() { $this->createMultipleNotifications(); $lastNotification = $this->user->getLastNotification(); - $notification = Notification::orderBy('created_at','desc')->first(); + $notification = Notification::orderBy('created_at', 'desc')->first(); - $this->assertEquals($notification->id,$lastNotification->id); + $this->assertEquals($notification->id, $lastNotification->id); } -} \ No newline at end of file +} diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index a26f890..fc0981b 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -1,11 +1,12 @@ 1, - 'type' => 'Fenos\Tests\Models\User' + 'type' => 'Fenos\Tests\Models\User', ]; /** - * Set Up Test + * Set Up Test. */ public function setUp() { @@ -36,113 +37,113 @@ public function setUp() } /** @test */ - function it_retrieve_notification_with_parsed_body() + public function it_retrieve_notification_with_parsed_body() { $extraValues = json_encode(['look' => 'Amazing']); $category = $this->createCategory(['text' => 'parse this {extra.look} value']); - $notification = $this->createNotification(['extra' => $extraValues,'category_id' => $category->id]); + $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); $notifications = $this->notification->getNotRead($notification->to->id); $bodyParsed = 'parse this Amazing value'; - $this->assertEquals($bodyParsed,$notifications[0]->text); + $this->assertEquals($bodyParsed, $notifications[0]->text); } /** @test */ - function it_retrieve_notification_by_limiting_the_number() + public function it_retrieve_notification_by_limiting_the_number() { $this->createMultipleNotifications(); // set polymorphic to true - app('config')->set('notifynder.polymorphic',true); + app('config')->set('notifynder.polymorphic', true); $notification = $this->createNotification(['extra' => 'Amazing']); $this->createMultipleNotifications(['to_id' => $notification->to_id]); $notifications = $this->notification->entity($this->to['type']) - ->getAll($notification->to->id,1); + ->getAll($notification->to->id, 1); - $this->assertCount(1,$notifications); + $this->assertCount(1, $notifications); } /** @test */ - function it_retrieve_notification_by_paginating_the_number() + public function it_retrieve_notification_by_paginating_the_number() { - app('config')->set('notifynder.polymorphic',false); + app('config')->set('notifynder.polymorphic', false); $extraValues = json_encode(['look' => 'Amazing']); $category = $this->createCategory(['text' => 'parse this {extra.look} value']); - $notification = $this->createNotification(['extra' => $extraValues,'category_id' => $category->id]); + $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); $this->createMultipleNotifications(['to_id' => $notification->to_id]); - $notifications = $this->notification->getNotRead($notification->to->id,5,1); + $notifications = $this->notification->getNotRead($notification->to->id, 5, 1); - $this->assertCount(5,$notifications); + $this->assertCount(5, $notifications); } /** * It will query adding the filter scope - * on of the category by name + * on of the category by name. * * @test */ - function it_will_query_for_notification_by_category_name() + public function it_will_query_for_notification_by_category_name() { - app('config')->set('notifynder.polymorphic',false); + app('config')->set('notifynder.polymorphic', false); $this->createMultipleNotifications(); - $category = $this->createCategory(['text' => 'parse this {extra.look} value','name' => 'text']); + $category = $this->createCategory(['text' => 'parse this {extra.look} value', 'name' => 'text']); $this->createMultipleNotifications(['category_id' => $category->id]); $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); - $notificationByCategory = $user->getNotifications(false,false,'desc', function($query) use ($category) { + $notificationByCategory = $user->getNotifications(false, false, 'desc', function ($query) use ($category) { $query->byCategory('text'); }); - $this->assertCount(10,$notificationByCategory); + $this->assertCount(10, $notificationByCategory); } /** * It will check that the fillable fields config option are - * allowing to save the model when resolved trough the ioc + * allowing to save the model when resolved trough the ioc. * * @test * @group f */ - function it_will_check_the_fillable_fields_options_are_allowing_to_save_the_model() + public function it_will_check_the_fillable_fields_options_are_allowing_to_save_the_model() { - app('config')->set('notifynder.additional_fields.fillable',[ - 'icon_type' + app('config')->set('notifynder.additional_fields.fillable', [ + 'icon_type', ]); $model = app(\Fenos\Notifynder\Models\Notification::class); $fillable = [ - 'to_id','to_type','from_id','from_type', - 'category_id','read','url','extra', 'expire_time', - 'icon_type' + 'to_id', 'to_type', 'from_id', 'from_type', + 'category_id', 'read', 'url', 'extra', 'expire_time', + 'icon_type', ]; - $this->assertEquals($fillable, $model->getFillable() ); + $this->assertEquals($fillable, $model->getFillable()); } /** @test */ - function it_retrieve_notification_with_parsed_body_and_multi_dots() + public function it_retrieve_notification_with_parsed_body_and_multi_dots() { - $extraValues = json_encode(['look' => 'Amazing', 'user' => ['last' => 'Doe', 'first' => 'John'],]); + $extraValues = json_encode(['look' => 'Amazing', 'user' => ['last' => 'Doe', 'first' => 'John']]); $category = $this->createCategory(['text' => 'parse this {extra.look} value from {extra.user.first} {extra.user.last}']); - $notification = $this->createNotification(['extra' => $extraValues,'category_id' => $category->id]); + $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); $notifications = $this->notification->getNotRead($notification->to->id); $bodyParsed = 'parse this Amazing value from John Doe'; - $this->assertEquals($bodyParsed,$notifications[0]->text); + $this->assertEquals($bodyParsed, $notifications[0]->text); } /** @test */ - function it_retrieve_notification_with_parsed_body_and_multi_dots_with_objects() + public function it_retrieve_notification_with_parsed_body_and_multi_dots_with_objects() { $user = new \Fenos\Tests\Models\User(['id' => '1']); $object = json_decode(json_encode(['last' => 'Doe', 'first' => 'John']), false); @@ -150,14 +151,14 @@ function it_retrieve_notification_with_parsed_body_and_multi_dots_with_objects() $this->assertInstanceOf(\Fenos\Tests\Models\User::class, $user); $this->assertInstanceOf(stdClass::class, $object); - $extraValues = json_encode(['look' => 'Amazing', 'user' => $user, 'object' => $object,]); + $extraValues = json_encode(['look' => 'Amazing', 'user' => $user, 'object' => $object]); $category = $this->createCategory(['text' => 'parse this {extra.look} value from User#{extra.user.id} ({extra.object.first} {extra.object.last})']); - $notification = $this->createNotification(['extra' => $extraValues,'category_id' => $category->id]); + $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); $notifications = $this->notification->getNotRead($notification->to->id); $bodyParsed = 'parse this Amazing value from User#1 (John Doe)'; - $this->assertEquals($bodyParsed,$notifications[0]->text); + $this->assertEquals($bodyParsed, $notifications[0]->text); } -} \ No newline at end of file +} diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php index 8c6be3d..3515181 100755 --- a/tests/integration/Notifications/NotifynderTest.php +++ b/tests/integration/Notifications/NotifynderTest.php @@ -1,14 +1,15 @@ createCategory(['name' => 'customs']); - $this->notifynder->extend('sendCustom', function($notification,$app) { - return new CustomDefaultSender($notification,$app->make('notifynder')); + $this->notifynder->extend('sendCustom', function ($notification, $app) { + return new CustomDefaultSender($notification, $app->make('notifynder')); }); $notifications = $this->notifynder @@ -41,11 +42,11 @@ function it_call_an_extended_method() ->to(1) ->sendCustom(); - $this->assertEquals('w',$notifications->url); + $this->assertEquals('w', $notifications->url); } /** @test */ - function it_send_a_notification_with_the_new_way() + public function it_send_a_notification_with_the_new_way() { $this->createCategory(['name' => 'custom']); @@ -56,12 +57,11 @@ function it_send_a_notification_with_the_new_way() ->to(1); $notifications = $this->notifynder->send($notifications); - $this->assertEquals('w',$notifications->url); + $this->assertEquals('w', $notifications->url); } - /** @test */ - function it_send_using_notifynder_as_an_array() + public function it_send_using_notifynder_as_an_array() { $this->createCategory(['name' => 'custom']); @@ -71,11 +71,11 @@ function it_send_using_notifynder_as_an_array() $this->notifynder['to'] = 1; $notification = $this->notifynder->send(); - $this->assertEquals('w',$notification->url); + $this->assertEquals('w', $notification->url); } /** @test */ - function it_send_using_notifynder_as_an_object() + public function it_send_using_notifynder_as_an_object() { $this->createCategory(['name' => 'custom']); @@ -86,13 +86,13 @@ function it_send_using_notifynder_as_an_object() $notifynder->to = 1; $notification = $notifynder->send(); - $this->assertEquals('w',$notification->url); + $this->assertEquals('w', $notification->url); } /** * @test */ - function it_store_extra_field_as_json() + public function it_store_extra_field_as_json() { $this->createCategory(['name' => 'custom']); @@ -106,24 +106,24 @@ function it_store_extra_field_as_json() ->to(1); $notifications = $this->notifynder->send($notifications); - $this->assertEquals($notifications->extra->toArray(),$extra); + $this->assertEquals($notifications->extra->toArray(), $extra); } /** - * It send multiple Notifications + * It send multiple Notifications. * * @method send * @group failing * @test */ - function it_send_multiple_notifications() + public function it_send_multiple_notifications() { Factory::times(10)->create(User::class); $this->createCategory(['name' => 'me']); $allUsers = User::all(); - $this->notifynder->loop($allUsers, function($builder,$user) { + $this->notifynder->loop($allUsers, function ($builder, $user) { $builder->category('me') ->url('you') @@ -135,6 +135,6 @@ function it_send_multiple_notifications() // should send 10 notifications $notifications = Notification::all(); - $this->assertCount(10,$notifications); + $this->assertCount(10, $notifications); } -} \ No newline at end of file +} diff --git a/tests/integration/Repositories/GroupCategoryReposutoryTest.php b/tests/integration/Repositories/GroupCategoryReposutoryTest.php index 207672a..2a92bfa 100755 --- a/tests/integration/Repositories/GroupCategoryReposutoryTest.php +++ b/tests/integration/Repositories/GroupCategoryReposutoryTest.php @@ -1,11 +1,12 @@ createCategory(); $group = $this->createGroup(); @@ -34,11 +35,11 @@ function it_add_a_category_to_a_group_id() $category->id ); - $this->assertEquals($group->categories[0]->name,$category->name); + $this->assertEquals($group->categories[0]->name, $category->name); } /** @test */ - function it_add_a_category_to_a_group_by_name() + public function it_add_a_category_to_a_group_by_name() { $category = $this->createCategory(); $group = $this->createGroup(); @@ -48,11 +49,11 @@ function it_add_a_category_to_a_group_by_name() $category->name ); - $this->assertEquals($group->categories[0]->name,$category->name); + $this->assertEquals($group->categories[0]->name, $category->name); } /** @test */ - function it_add_multiple_categories_to_a_group_by_name() + public function it_add_multiple_categories_to_a_group_by_name() { $category1 = $this->createCategory(); $category2 = $this->createCategory(); @@ -63,6 +64,6 @@ function it_add_multiple_categories_to_a_group_by_name() [$category1->name, $category2->name] ); - $this->assertCount(2,$group->categories); + $this->assertCount(2, $group->categories); } -} \ No newline at end of file +} diff --git a/tests/integration/Repositories/GroupRepositoryTest.php b/tests/integration/Repositories/GroupRepositoryTest.php index 278a8e6..d62b307 100755 --- a/tests/integration/Repositories/GroupRepositoryTest.php +++ b/tests/integration/Repositories/GroupRepositoryTest.php @@ -1,12 +1,13 @@ createGroup(); $findGroup = $this->group->find($group->id); - $this->assertEquals($group->id,$findGroup->id); + $this->assertEquals($group->id, $findGroup->id); } /** @test */ - function it_find_a_group_by_name() + public function it_find_a_group_by_name() { $group_name = 'mygroup'; $this->createGroup(['name' => $group_name]); $group = $this->group->findByName($group_name); - $this->assertEquals($group_name,$group->name); + $this->assertEquals($group_name, $group->name); } /** @test */ - function it_create_a_group() + public function it_create_a_group() { $groupData = 'mygroup'; $group = $this->group->create($groupData); - $this->assertEquals($groupData,$group->name); + $this->assertEquals($groupData, $group->name); } /** @test */ - function it_delete_a_group_by_id() + public function it_delete_a_group_by_id() { $group = $this->createGroup(); @@ -63,4 +64,4 @@ function it_delete_a_group_by_id() $this->assertCount(0, NotificationGroup::all()); } -} \ No newline at end of file +} diff --git a/tests/integration/Repositories/NotificationCategoryDBTest.php b/tests/integration/Repositories/NotificationCategoryDBTest.php index 203ebf6..8510680 100755 --- a/tests/integration/Repositories/NotificationCategoryDBTest.php +++ b/tests/integration/Repositories/NotificationCategoryDBTest.php @@ -1,14 +1,13 @@ categoryRepo = app('notifynder.category.repository'); } - + /** @test */ - function it_find_a_category_by_id() + public function it_find_a_category_by_id() { $record = $this->createCategory(); $category = $this->categoryRepo->find($record->id); - $this->assertEquals(1,$category->id); + $this->assertEquals(1, $category->id); } /** @test */ - function it_find_a_category_by_name() + public function it_find_a_category_by_name() { - $categoryName = "test.category"; + $categoryName = 'test.category'; $this->createCategory(['name' => $categoryName]); $category = $this->categoryRepo->findByName($categoryName); - $this->assertEquals($categoryName,$category->name); + $this->assertEquals($categoryName, $category->name); } /** @test */ - function it_find_categories_giving_multiple_names() + public function it_find_categories_giving_multiple_names() { - $categoryNames = ['test.first','test.second']; + $categoryNames = ['test.first', 'test.second']; $this->createCategory(['name' => $categoryNames[0]]); $this->createCategory(['name' => $categoryNames[1]]); $categories = $this->categoryRepo->findByNames($categoryNames); - $this->assertCount(2,$categories); + $this->assertCount(2, $categories); } /** @test */ - function it_add_a_new_category() + public function it_add_a_new_category() { $categoryData = Factory::build('Fenos\Notifynder\Models\NotificationCategory'); - $createCategory = $this->categoryRepo->add($categoryData->name,$categoryData->text); + $createCategory = $this->categoryRepo->add($categoryData->name, $categoryData->text); - $this->assertEquals($categoryData->name,$createCategory->name); + $this->assertEquals($categoryData->name, $createCategory->name); } /** @test */ - function it_delete_a_category_by_id() + public function it_delete_a_category_by_id() { $categoryToDelete = $this->createCategory(); @@ -80,11 +79,11 @@ function it_delete_a_category_by_id() $tryToFindThatCategory = $this->categoryRepo->find($categoryToDelete->id); - $this->assertEquals($tryToFindThatCategory,null); + $this->assertEquals($tryToFindThatCategory, null); } /** @test */ - function it_delete_a_category_by_name() + public function it_delete_a_category_by_name() { $categoryToDelete = $this->createCategory(); @@ -92,6 +91,6 @@ function it_delete_a_category_by_name() $tryToFindThatCategory = $this->categoryRepo->findByName($categoryToDelete->name); - $this->assertEquals($tryToFindThatCategory,null); + $this->assertEquals($tryToFindThatCategory, null); } -} \ No newline at end of file +} diff --git a/tests/integration/Repositories/NotificationRepositoryDBTest.php b/tests/integration/Repositories/NotificationRepositoryDBTest.php index 01c3de4..ab01425 100755 --- a/tests/integration/Repositories/NotificationRepositoryDBTest.php +++ b/tests/integration/Repositories/NotificationRepositoryDBTest.php @@ -4,8 +4,8 @@ use Fenos\Notifynder\Notifications\NotificationRepository; use Laracasts\TestDummy\Factory; -class NotificationRepositoryDBTest extends TestCaseDB { - +class NotificationRepositoryDBTest extends TestCaseDB +{ use CreateModels; /** @@ -18,7 +18,7 @@ class NotificationRepositoryDBTest extends TestCaseDB { */ protected $to = [ 'id' => 1, - 'type' => 'User' + 'type' => 'User', ]; /** @@ -32,7 +32,7 @@ class NotificationRepositoryDBTest extends TestCaseDB { protected $to_id = 1; /** - * SetUp Tests + * SetUp Tests. */ public function setUp() { @@ -42,30 +42,30 @@ public function setUp() } /** @test */ - function it_find_a_notification_by_id() + public function it_find_a_notification_by_id() { $notificationToSearch = $this->createNotification(); $notification = $this->notificationRepo->find($notificationToSearch->id); - $this->assertEquals($notificationToSearch->id,$notification->id); + $this->assertEquals($notificationToSearch->id, $notification->id); } /** @test */ - function it_send_a_single_notification() + public function it_send_a_single_notification() { $notificationToSend = $this->buildNotification(); $notification = $this->notificationRepo->storeSingle($notificationToSend); - $this->assertEquals($notificationToSend['to_id'],$notification->to_id); - $this->assertEquals($notificationToSend['to_type'],$notification->to_type); + $this->assertEquals($notificationToSend['to_id'], $notification->to_id); + $this->assertEquals($notificationToSend['to_type'], $notification->to_type); } /** @test * @group fails */ - function it_send_multiple_notification() + public function it_send_multiple_notification() { $notificationsToSend[0] = $this->buildNotification(); $notificationsToSend[1] = $this->buildNotification(); @@ -74,98 +74,98 @@ function it_send_multiple_notification() $notifications = Notification::all(); - $this->assertCount(2,$notifications); - $this->assertEquals(2,$storeMultipleNotificaations); + $this->assertCount(2, $notifications); + $this->assertEquals(2, $storeMultipleNotificaations); } /** @test */ - function it_read_one_notification_by_id() + public function it_read_one_notification_by_id() { $notificationToRead = $this->createNotification(); $notificationRead = $this->notificationRepo->readOne($notificationToRead); - $this->assertEquals(1,$notificationRead->read); + $this->assertEquals(1, $notificationRead->read); } /** @test */ - function it_read_limit_the_number_of_notifications_of_the_given_entity() + public function it_read_limit_the_number_of_notifications_of_the_given_entity() { $this->createMultipleNotifications(); $readFive = $this->notificationRepo->readLimit( - $this->to['id'],$this->to['type'],5,'asc' + $this->to['id'], $this->to['type'], 5, 'asc' ); $notificationsRead = Notification::whereRead(1)->get(); - $this->assertEquals(5,$readFive); - $this->assertCount(5,$notificationsRead); + $this->assertEquals(5, $readFive); + $this->assertCount(5, $notificationsRead); } /** @test */ - function it_read_all_the_notifications_of_the_given_entity() + public function it_read_all_the_notifications_of_the_given_entity() { $this->createMultipleNotifications(); $notificationRead = $this->notificationRepo->readAll( - $this->to['id'],$this->to['type'] + $this->to['id'], $this->to['type'] ); - $this->assertEquals(10,$notificationRead); + $this->assertEquals(10, $notificationRead); } /** @test */ - function it_delete_a_notification_by_id() + public function it_delete_a_notification_by_id() { $notificationToDelete = $this->createNotification(); $deleted = $this->notificationRepo->delete($notificationToDelete->id); - $this->assertEquals(1,$deleted); - $this->assertCount(0,Notification::all()); + $this->assertEquals(1, $deleted); + $this->assertCount(0, Notification::all()); } /** @test */ - function it_delete_all_the_notification_of_the_given_entity() + public function it_delete_all_the_notification_of_the_given_entity() { $this->createMultipleNotifications(); $deleted = $this->notificationRepo->deleteAll( - $this->to['id'],$this->to['type'] + $this->to['id'], $this->to['type'] ); - $this->assertEquals(10,$deleted); - $this->assertCount(0,Notification::all()); + $this->assertEquals(10, $deleted); + $this->assertCount(0, Notification::all()); } /** @test */ - function it_delete_notifications_limit_the_number_of_the_given_entity() + public function it_delete_notifications_limit_the_number_of_the_given_entity() { $this->createMultipleNotifications(); $notificationsDeleted = $this->notificationRepo->deleteLimit( - $this->to['id'],$this->to['type'],5,'asc' + $this->to['id'], $this->to['type'], 5, 'asc' ); - $this->assertEquals(5,$notificationsDeleted); - $this->assertCount(5,Notification::all()); + $this->assertEquals(5, $notificationsDeleted); + $this->assertCount(5, Notification::all()); } /** @test */ - function it_count_notification_not_read() + public function it_count_notification_not_read() { $this->createMultipleNotifications(); $countNotRead = $this->notificationRepo->countNotRead( - $this->to['id'],$this->to['type'] + $this->to['id'], $this->to['type'] ); - $this->assertEquals($this->multiNotificationsNumber,$countNotRead); + $this->assertEquals($this->multiNotificationsNumber, $countNotRead); } /** @test */ - function it_delete_all_notification_by_category() + public function it_delete_all_notification_by_category() { $category = $this->createCategory(['name' => 'test']); @@ -179,37 +179,37 @@ function it_delete_all_notification_by_category() } /** @test */ - function it_delete_all_notification_expired_by_category_name() + public function it_delete_all_notification_expired_by_category_name() { $category = $this->createCategory(['name' => 'test']); $this->createNotification([ 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->subDays(1) + 'expire_time' => Carbon\Carbon::now()->subDays(1), ]); $this->createNotification([ 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->subDays(1) + 'expire_time' => Carbon\Carbon::now()->subDays(1), ]); $this->createNotification([ 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->subDays(1) + 'expire_time' => Carbon\Carbon::now()->subDays(1), ]); $this->createNotification([ 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->addDays(1) + 'expire_time' => Carbon\Carbon::now()->addDays(1), ]); - $this->notificationRepo->deleteByCategory($category->name,true); + $this->notificationRepo->deleteByCategory($category->name, true); $this->assertCount(1, Notification::all()); } /** @test */ - function it_get_the_last_notificiation_sent() + public function it_get_the_last_notificiation_sent() { $category = $this->createCategory(['name' => 'test']); @@ -217,23 +217,23 @@ function it_get_the_last_notificiation_sent() 'category_id' => $category->id, 'url' => 'first', 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(1) + 'created_at' => Carbon\Carbon::now()->addDay(1), ]); $this->createNotification([ 'category_id' => $category->id, 'url' => 'second', 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(2) + 'created_at' => Carbon\Carbon::now()->addDay(2), ]); - $notification = $this->notificationRepo->getLastNotification(1,null); + $notification = $this->notificationRepo->getLastNotification(1, null); - $this->assertEquals('second',$notification->url); + $this->assertEquals('second', $notification->url); } /** @test */ - function it_get_the_last_notificiation_sent_by_category() + public function it_get_the_last_notificiation_sent_by_category() { $category1 = $this->createCategory(['name' => 'test']); $category2 = $this->createCategory(['name' => 'test2']); @@ -242,40 +242,38 @@ function it_get_the_last_notificiation_sent_by_category() 'category_id' => $category1->id, 'url' => 'first', 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(1) + 'created_at' => Carbon\Carbon::now()->addDay(1), ]); $this->createNotification([ 'category_id' => $category1->id, 'url' => 'second', 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(2) + 'created_at' => Carbon\Carbon::now()->addDay(2), ]); $this->createNotification([ 'category_id' => $category2->id, 'url' => 'third', 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(3) + 'created_at' => Carbon\Carbon::now()->addDay(3), ]); - $notificationByName = $this->notificationRepo->getLastNotificationByCategory('test',1,null); - $notificationById = $this->notificationRepo->getLastNotificationByCategory($category1->id,1,null); + $notificationByName = $this->notificationRepo->getLastNotificationByCategory('test', 1, null); + $notificationById = $this->notificationRepo->getLastNotificationByCategory($category1->id, 1, null); - $this->assertEquals('second',$notificationByName->url); - $this->assertEquals('second',$notificationById->url); + $this->assertEquals('second', $notificationByName->url); + $this->assertEquals('second', $notificationById->url); } /** - * Shortcut to build a new notification + * Shortcut to build a new notification. * * @param array $data * @return array */ protected function buildNotification(array $data = []) { - return Factory::build(Notification::class,$data)->toArray(); + return Factory::build(Notification::class, $data)->toArray(); } - - -} \ No newline at end of file +} diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index ad6070a..3a1aac3 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -1,17 +1,15 @@ createCategory(['name' => $category_name]); @@ -66,15 +64,15 @@ function it_send_now_a_single_notification() } /** @test */ - function it_send_now_a_mutiple_notification() + public function it_send_now_a_mutiple_notification() { $category_name = 'my.category'; $this->createCategory(['name' => $category_name]); - $user_ids = [1,2]; + $user_ids = [1, 2]; $sendMultiple = $this->builder->loop($user_ids, - function(NotifynderBuilder $builder, $value) use ($category_name) { + function (NotifynderBuilder $builder, $value) use ($category_name) { return $builder->category($category_name) ->to($value) @@ -90,7 +88,7 @@ function(NotifynderBuilder $builder, $value) use ($category_name) { } /** @test */ - function it_send_a_group_of_notification() + public function it_send_a_group_of_notification() { $group = $this->createGroup(['name' => 'mygroud']); $category1 = $this->createCategory(); @@ -103,20 +101,20 @@ function it_send_a_group_of_notification() $category3->name ); - $this->senders->sendGroup($group->name,[ + $this->senders->sendGroup($group->name, [ 'from_id' => 1, 'to_id' => 2, - 'url' => 'www.notifynder.io' + 'url' => 'www.notifynder.io', ]); - $this->assertCount(3,Notification::all()); + $this->assertCount(3, Notification::all()); } /** @test */ - function it_send_with_an_custom_sender() + public function it_send_with_an_custom_sender() { - $this->senders->extend('sendCustom', function($notification,$app) { - return new CustomDefaultSender($notification,$app->make('notifynder')); + $this->senders->extend('sendCustom', function ($notification, $app) { + return new CustomDefaultSender($notification, $app->make('notifynder')); }); $category_name = 'my.category'; @@ -132,4 +130,4 @@ function it_send_with_an_custom_sender() $this->assertCount(1, Notification::all()); } -} \ No newline at end of file +} diff --git a/tests/integration/Translator/TranslatorTest.php b/tests/integration/Translator/TranslatorTest.php index 07f0f57..5a10eca 100755 --- a/tests/integration/Translator/TranslatorTest.php +++ b/tests/integration/Translator/TranslatorTest.php @@ -3,10 +3,10 @@ use Fenos\Notifynder\Translator\TranslatorManager; /** - * Class TranslatorTest + * Class TranslatorTest. */ -class TranslatorTest extends TestCaseDB { - +class TranslatorTest extends TestCaseDB +{ use CreateModels; /** @@ -15,23 +15,23 @@ class TranslatorTest extends TestCaseDB { protected $translator; /** - * Set Up + * Set Up. */ public function setUp() { parent::setUp(); - $translations = require('translations.php'); + $translations = require 'translations.php'; - app('config')->set('notifynder.translations',$translations); + app('config')->set('notifynder.translations', $translations); $this->translator = app('notifynder.translator'); } /** @test */ - function it_translate_a_notification() + public function it_translate_a_notification() { - $translation = $this->translator->translate('it','welcome'); + $translation = $this->translator->translate('it', 'welcome'); - $this->assertEquals('benvenuto',$translation); + $this->assertEquals('benvenuto', $translation); } -} \ No newline at end of file +} diff --git a/tests/integration/Translator/translations.php b/tests/integration/Translator/translations.php index 74be29f..701def0 100755 --- a/tests/integration/Translator/translations.php +++ b/tests/integration/Translator/translations.php @@ -3,7 +3,7 @@ return [ 'it' => [ - 'welcome' => 'benvenuto' - ] + 'welcome' => 'benvenuto', + ], -]; \ No newline at end of file +]; diff --git a/tests/migrations/2014_08_01_164248_create_users_table.php b/tests/migrations/2014_08_01_164248_create_users_table.php index 2973ba7..58e6bd1 100755 --- a/tests/migrations/2014_08_01_164248_create_users_table.php +++ b/tests/migrations/2014_08_01_164248_create_users_table.php @@ -3,31 +3,30 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateUsersTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('users', function(Blueprint $table) { +class CreateUsersTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('surname'); $table->timestamps(); }); - } + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { Schema::drop('users'); - } - + } } diff --git a/tests/models/User.php b/tests/models/User.php index 76a861b..9957d47 100755 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -1,10 +1,12 @@ - Date: Tue, 17 May 2016 12:50:50 +0200 Subject: [PATCH 067/210] Create .codeclimate.yml --- .codeclimate.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..276e693 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,21 @@ +engines: + duplication: + enabled: true + config: + languages: + php: + mass_threshold: 40 + fixme: + enabled: true + phpmd: + enabled: true + checks: + CleanCode/StaticAccess: + enabled: false + Design/CouplingBetweenObjects: + enabled: false +ratings: + paths: + - "src/Notifynder/**.php" +exclude_paths: + - tests/ From 9ad924fccb3a5d39a2c610c657449cd4fcc14c48 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 12:52:18 +0200 Subject: [PATCH 068/210] Update .codeclimate.yml --- .codeclimate.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.codeclimate.yml b/.codeclimate.yml index 276e693..5c61814 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -19,3 +19,4 @@ ratings: - "src/Notifynder/**.php" exclude_paths: - tests/ + - spec/ From b3a0408a8064ce316331cf80c9a2b6f5c4c9ae2a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 12:53:52 +0200 Subject: [PATCH 069/210] Update .codeclimate.yml --- .codeclimate.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.codeclimate.yml b/.codeclimate.yml index 5c61814..4eedeee 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -12,6 +12,8 @@ engines: checks: CleanCode/StaticAccess: enabled: false + Design/TooManyPublicMethods: + enabled: false Design/CouplingBetweenObjects: enabled: false ratings: From ad4f6d32a0d21f76d9a6317743dbe432c5f3b469 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 12:55:59 +0200 Subject: [PATCH 070/210] Update .codeclimate.yml --- .codeclimate.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.codeclimate.yml b/.codeclimate.yml index 4eedeee..83f35da 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -22,3 +22,5 @@ ratings: exclude_paths: - tests/ - spec/ + - src/migrations/ + - src/config/ From b8d077f97dfec968ed7b29c3e5a952de110d863d Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 13:57:52 +0200 Subject: [PATCH 071/210] fix "The parameter ... is not named in camelCase." --- src/Notifynder/Contracts/NotificationDB.php | 46 +++++------ .../Notifications/NotificationRepository.php | 76 +++++++++---------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/Notifynder/Contracts/NotificationDB.php b/src/Notifynder/Contracts/NotificationDB.php index 7d0b595..c323539 100755 --- a/src/Notifynder/Contracts/NotificationDB.php +++ b/src/Notifynder/Contracts/NotificationDB.php @@ -13,10 +13,10 @@ interface NotificationDB extends StoreNotification /** * Find notification by id. * - * @param $notification_id + * @param $notificationId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function find($notification_id); + public function find($notificationId); /** * Make Read One Notification. @@ -30,72 +30,72 @@ public function readOne(Notification $notification); * Read notifications in base the number * Given. * - * @param $to_id + * @param $toId * @param $entity * @param $numbers * @param $order * @return int */ - public function readLimit($to_id, $entity, $numbers, $order); + public function readLimit($toId, $entity, $numbers, $order); /** * Make read all notification not read. * - * @param $to_id + * @param $toId * @param $entity * @return int */ - public function readAll($to_id, $entity); + public function readAll($toId, $entity); /** * Delete a notification giving the id * of it. * - * @param $notification_id + * @param $notificationId * @return bool */ - public function delete($notification_id); + public function delete($notificationId); /** * Delete All notifications about the * current user. * - * @param $to_id int + * @param $toId int * @param $entity * @return bool */ - public function deleteAll($to_id, $entity); + public function deleteAll($toId, $entity); /** * Delete All notifications from a * defined category. * - * @param $category_name + * @param $categoryName * @param $expired Bool * @return bool */ - public function deleteByCategory($category_name, $expired = false); + public function deleteByCategory($categoryName, $expired = false); /** * Delete numbers of notifications equals * to the number passing as 2 parameter of * the current user. * - * @param $user_id int + * @param $userId int * @param $entity * @param $number int * @param $order string * @return int * @throws \Exception */ - public function deleteLimit($user_id, $entity, $number, $order); + public function deleteLimit($userId, $entity, $number, $order); /** * Retrive notifications not Read * You can also limit the number of * Notification if you don't it will get all. * - * @param $to_id + * @param $toId * @param $entity * @param $limit * @param int|null $paginate @@ -104,7 +104,7 @@ public function deleteLimit($user_id, $entity, $number, $order); * @return mixed */ public function getNotRead( - $to_id, + $toId, $entity, $limit, $paginate = null, @@ -118,7 +118,7 @@ public function getNotRead( * You can also limit the number of * Notifications if you don't, it will get all. * - * @param $to_id + * @param $toId * @param $entity * @param null $limit * @param int|null $paginate @@ -127,7 +127,7 @@ public function getNotRead( * @return mixed */ public function getAll( - $to_id, + $toId, $entity, $limit = null, $paginate = null, @@ -139,12 +139,12 @@ public function getAll( * get number Notifications * not read. * - * @param $to_id + * @param $toId * @param $entity * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id, $entity, Closure $filterScope = null); + public function countNotRead($toId, $entity, Closure $filterScope = null); /** * Get last notification of the current @@ -155,17 +155,17 @@ public function countNotRead($to_id, $entity, Closure $filterScope = null); * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id, $entity, Closure $filterScope = null); + public function getLastNotification($toId, $entity, Closure $filterScope = null); /** * Get last notification of the current * entity of a specific category. * * @param $category - * @param $to_id + * @param $toId * @param $entity * @param Closure $filterScope * @return mixed */ - public function getLastNotificationByCategory($category, $to_id, $entity, Closure $filterScope = null); + public function getLastNotificationByCategory($category, $toId, $entity, Closure $filterScope = null); } diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index 0751725..88299f8 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -40,12 +40,12 @@ public function __construct( /** * Find notification by id. * - * @param $notification_id + * @param $notificationId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function find($notification_id) + public function find($notificationId) { - return $this->notification->find($notification_id); + return $this->notification->find($notificationId); } /** @@ -94,16 +94,16 @@ public function readOne(Notification $notification) * Read notifications in base the number * Given. * - * @param $to_id + * @param $toId * @param $entity * @param $numbers * @param $order * @return int */ - public function readLimit($to_id, $entity, $numbers, $order) + public function readLimit($toId, $entity, $numbers, $order) { $notifications = $this->notification->withNotRead() - ->wherePolymorphic($to_id, $entity) + ->wherePolymorphic($toId, $entity) ->limit($numbers) ->orderBy('id', $order) ->lists('id'); @@ -115,14 +115,14 @@ public function readLimit($to_id, $entity, $numbers, $order) /** * Make read all notification not read. * - * @param $to_id + * @param $toId * @param $entity * @return int */ - public function readAll($to_id, $entity) + public function readAll($toId, $entity) { return $this->notification->withNotRead() - ->wherePolymorphic($to_id, $entity) + ->wherePolymorphic($toId, $entity) ->update(['read' => 1]); } @@ -130,12 +130,12 @@ public function readAll($to_id, $entity) * Delete a notification giving the id * of it. * - * @param $notification_id + * @param $notificationId * @return bool */ - public function delete($notification_id) + public function delete($notificationId) { - return $this->notification->where('id', $notification_id)->delete(); + return $this->notification->where('id', $notificationId)->delete(); } /** @@ -146,13 +146,13 @@ public function delete($notification_id) * @param $entity * @return bool */ - public function deleteAll($to_id, $entity) + public function deleteAll($toId, $entity) { $query = $this->db->table( $this->notification->getTable() ); - return $this->notification->scopeWherePolymorphic($query, $to_id, $entity) + return $this->notification->scopeWherePolymorphic($query, $toId, $entity) ->delete(); } @@ -160,16 +160,16 @@ public function deleteAll($to_id, $entity) * Delete All notifications from a * defined category. * - * @param $category_name int + * @param $categoryName int * @param $expired Bool * @return bool */ - public function deleteByCategory($category_name, $expired = false) + public function deleteByCategory($categoryName, $expired = false) { $query = $this->notification->whereHas( 'body', - function ($q) use ($category_name) { - $q->where('name', $category_name); + function ($query) use ($categoryName) { + $query->where('name', $categoryName); } ); @@ -185,27 +185,27 @@ function ($q) use ($category_name) { * to the number passing as 2 parameter of * the current user. * - * @param $user_id int + * @param $userId int * @param $entity * @param $number int * @param $order string * @return int * @throws \Exception */ - public function deleteLimit($user_id, $entity, $number, $order) + public function deleteLimit($userId, $entity, $number, $order) { - $notifications_ids = $this->notification - ->wherePolymorphic($user_id, $entity) + $notificationsIds = $this->notification + ->wherePolymorphic($userId, $entity) ->orderBy('id', $order) ->select('id') ->limit($number) ->lists('id'); - if (count($notifications_ids) == 0) { + if (count($notificationsIds) == 0) { return false; } - return $this->notification->whereIn('id', $notifications_ids) + return $this->notification->whereIn('id', $notificationsIds) ->delete(); } @@ -214,7 +214,7 @@ public function deleteLimit($user_id, $entity, $number, $order) * You can also limit the number of * Notification if you don't it will get all. * - * @param $to_id + * @param $toId * @param $entity * @param int|null $limit * @param int|null $paginate @@ -223,7 +223,7 @@ public function deleteLimit($user_id, $entity, $number, $order) * @return mixed */ public function getNotRead( - $to_id, + $toId, $entity, $limit = null, $paginate = null, @@ -231,7 +231,7 @@ public function getNotRead( Closure $filterScope = null ) { $query = $this->notification->with('body', 'from') - ->wherePolymorphic($to_id, $entity) + ->wherePolymorphic($toId, $entity) ->withNotRead() ->orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); @@ -255,7 +255,7 @@ public function getNotRead( * You can also limit the number of * Notifications if you don't, it will get all. * - * @param $to_id + * @param $toId * @param $entity * @param null $limit * @param int|null $paginate @@ -264,7 +264,7 @@ public function getNotRead( * @return mixed */ public function getAll( - $to_id, + $toId, $entity, $limit = null, $paginate = null, @@ -272,7 +272,7 @@ public function getAll( Closure $filterScope = null ) { $query = $this->notification->with('body', 'from') - ->wherePolymorphic($to_id, $entity) + ->wherePolymorphic($toId, $entity) ->orderBy('read', 'ASC') ->orderBy('created_at', $orderDate); @@ -293,14 +293,14 @@ public function getAll( * get number Notifications * not read. * - * @param $to_id + * @param $toId * @param $entity * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id, $entity, Closure $filterScope = null) + public function countNotRead($toId, $entity, Closure $filterScope = null) { - $query = $this->notification->wherePolymorphic($to_id, $entity) + $query = $this->notification->wherePolymorphic($toId, $entity) ->withNotRead() ->select($this->db->raw('Count(*) as notRead')); @@ -313,14 +313,14 @@ public function countNotRead($to_id, $entity, Closure $filterScope = null) * Get last notification of the current * entity. * - * @param $to_id + * @param $toId * @param $entity * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id, $entity, Closure $filterScope = null) + public function getLastNotification($toId, $entity, Closure $filterScope = null) { - $query = $this->notification->wherePolymorphic($to_id, $entity) + $query = $this->notification->wherePolymorphic($toId, $entity) ->orderBy('created_at', 'DESC'); $query = $this->applyFilter($filterScope, $query); @@ -338,10 +338,10 @@ public function getLastNotification($to_id, $entity, Closure $filterScope = null * @param Closure $filterScope * @return mixed */ - public function getLastNotificationByCategory($category, $to_id, $entity, Closure $filterScope = null) + public function getLastNotificationByCategory($category, $toId, $entity, Closure $filterScope = null) { $query = $this->notification - ->wherePolymorphic($to_id, $entity) + ->wherePolymorphic($toId, $entity) ->byCategory($category) ->orderBy('created_at', 'desc'); From 211fabb25a16df94de75ce6d3d2046e27e3e3b59 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 14:06:37 +0200 Subject: [PATCH 072/210] fix "The parameter ... is not named in camelCase." --- .../Contracts/NotifynderDispatcher.php | 4 +- src/Notifynder/Contracts/NotifynderGroup.php | 20 ++--- .../Contracts/NotifynderGroupCategoryDB.php | 16 ++-- .../Contracts/NotifynderGroupDB.php | 8 +- .../Contracts/NotifynderNotification.php | 46 +++++------ src/Notifynder/Contracts/NotifynderSender.php | 4 +- .../Groups/GroupCategoryRepository.php | 26 +++---- src/Notifynder/Groups/GroupManager.php | 32 ++++---- src/Notifynder/Groups/GroupRepository.php | 12 +-- src/Notifynder/Handler/Dispatcher.php | 6 +- .../Notifications/NotificationManager.php | 78 +++++++++---------- src/Notifynder/Senders/SenderManager.php | 6 +- 12 files changed, 129 insertions(+), 129 deletions(-) diff --git a/src/Notifynder/Contracts/NotifynderDispatcher.php b/src/Notifynder/Contracts/NotifynderDispatcher.php index ef15b8e..4dbb852 100755 --- a/src/Notifynder/Contracts/NotifynderDispatcher.php +++ b/src/Notifynder/Contracts/NotifynderDispatcher.php @@ -15,11 +15,11 @@ interface NotifynderDispatcher * * @param Notifynder $notifynder * @param string $eventName - * @param string $category_name + * @param string $categoryName * @param mixed|null $values * @return mixed|null */ - public function fire(Notifynder $notifynder, $eventName, $category_name = null, $values = []); + public function fire(Notifynder $notifynder, $eventName, $categoryName = null, $values = []); /** * Deletegate events to categories. diff --git a/src/Notifynder/Contracts/NotifynderGroup.php b/src/Notifynder/Contracts/NotifynderGroup.php index c132e8e..5aad14f 100755 --- a/src/Notifynder/Contracts/NotifynderGroup.php +++ b/src/Notifynder/Contracts/NotifynderGroup.php @@ -12,40 +12,40 @@ interface NotifynderGroup /** * Find a group by id. * - * @param $group_id + * @param $groupId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static * @throws \Fenos\Notifynder\Exceptions\NotifynderGroupNotFoundException */ - public function findById($group_id); + public function findById($groupId); /** * Find a group By name. * - * @param $group_name + * @param $groupName * @return mixed * @throws \Fenos\Notifynder\Exceptions\NotifynderGroupNotFoundException */ - public function findByName($group_name); + public function findByName($groupName); /** * Add category to a group * giving the ids of them. * - * @param $gorup_id - * @param $category_id + * @param $groupId + * @param $categoryId * @return mixed */ - public function addCategoryToGroupById($gorup_id, $category_id); + public function addCategoryToGroupById($groupId, $categoryId); /** * Add category to a group * giving the ids of them. * - * @param $gorup_name - * @param $category_name + * @param $groupName + * @param $categoryName * @return mixed */ - public function addCategoryToGroupByName($gorup_name, $category_name); + public function addCategoryToGroupByName($groupName, $categoryName); /** * Add Multiple categories in a group diff --git a/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php b/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php index 5c28580..0d51cec 100755 --- a/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php +++ b/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php @@ -10,30 +10,30 @@ interface NotifynderGroupCategoryDB /** * Add a category in a group. * - * @param $group_id - * @param $category_id + * @param $groupId + * @param $categoryId * @internal param \Fenos\Notifynder\Models\NotificationCategory $category * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function addCategoryToGroupById($group_id, $category_id); + public function addCategoryToGroupById($groupId, $categoryId); /** * Add a category in a group * by names given. * - * @param $group_name - * @param $category_name + * @param $groupName + * @param $categoryName * @return mixed */ - public function addCategoryToGroupByName($group_name, $category_name); + public function addCategoryToGroupByName($groupName, $categoryName); /** * Add multiple categories by them names * to a group. * - * @param $group_name + * @param $groupName * @param $names * @return mixed */ - public function addMultipleCategoriesToGroup($group_name, array $names); + public function addMultipleCategoriesToGroup($groupName, array $names); } diff --git a/src/Notifynder/Contracts/NotifynderGroupDB.php b/src/Notifynder/Contracts/NotifynderGroupDB.php index 7f6f8c2..de44218 100755 --- a/src/Notifynder/Contracts/NotifynderGroupDB.php +++ b/src/Notifynder/Contracts/NotifynderGroupDB.php @@ -10,10 +10,10 @@ interface NotifynderGroupDB /** * Find a group by ID. * - * @param $group_id + * @param $groupId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function find($group_id); + public function find($groupId); /** * Find a group by name. @@ -34,8 +34,8 @@ public function create($name); /** * Delete a group. * - * @param $group_id + * @param $groupId * @return mixed */ - public function delete($group_id); + public function delete($groupId); } diff --git a/src/Notifynder/Contracts/NotifynderNotification.php b/src/Notifynder/Contracts/NotifynderNotification.php index 45acb1e..ecbeb26 100755 --- a/src/Notifynder/Contracts/NotifynderNotification.php +++ b/src/Notifynder/Contracts/NotifynderNotification.php @@ -21,61 +21,61 @@ public function entity($name); /** * Find a notification by ID. * - * @param $notification_id + * @param $notificationId * @return NotificationModel|\Illuminate\Database\Eloquent\Model|static * @throws \Fenos\Notifynder\Exceptions\NotificationNotFoundException */ - public function find($notification_id); + public function find($notificationId); /** * Make read one notification giving * the ID of it. * - * @param $notification_id + * @param $notificationId * @return bool|\Fenos\Notifynder\Models\Notification */ - public function readOne($notification_id); + public function readOne($notificationId); /** * Read notifications in base the number * Given. * - * @param $to_id + * @param $toId * @param $numbers * @param string $order * @return mixed */ - public function readLimit($to_id, $numbers, $order = 'ASC'); + public function readLimit($toId, $numbers, $order = 'ASC'); /** * Read all notification of the * given entity. * - * @param $to_id + * @param $toId * @return Number */ - public function readAll($to_id); + public function readAll($toId); /** * Delete a notification giving the id * of it. * - * @param $notification_id + * @param $notificationId * @return bool */ - public function delete($notification_id); + public function delete($notificationId); /** * Delete numbers of notifications equals * to the number passing as 2 parameter of * the current user. * - * @param $entity_id + * @param $entityId * @param $number * @param $order * @return mixed */ - public function deleteLimit($entity_id, $number, $order); + public function deleteLimit($entityId, $number, $order); /** * Delete all notification of a given @@ -84,30 +84,30 @@ public function deleteLimit($entity_id, $number, $order); * @param $entity_id * @return bool */ - public function deleteAll($entity_id); + public function deleteAll($entityId); /** * Delete All notifications from a * defined category. * - * @param $category_name string + * @param $categoryName string * @param $expired Bool * @return bool */ - public function deleteByCategory($category_name, $expired = false); + public function deleteByCategory($categoryName, $expired = false); /** * Get notifications not read * of the entity given. * - * @param $to_id + * @param $toId * @param $limit * @param $paginate * @param string $orderDate * @param Closure $filterScope * @return mixed */ - public function getNotRead($to_id, $limit, $paginate, $orderDate = 'desc', Closure $filterScope = null); + public function getNotRead($toId, $limit, $paginate, $orderDate = 'desc', Closure $filterScope = null); /** * Get All notifications. @@ -125,22 +125,22 @@ public function getAll($to_id, $limit, $paginate, $orderDate = 'desc', Closure $ * Get last notification of the * given entity. * - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id, Closure $filterScope = null); + public function getLastNotification($toId, Closure $filterScope = null); /** * Get last notification of the * given entity of the specific category. * * @param $category - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function getLastNotificationByCategory($category, $to_id, Closure $filterScope = null); + public function getLastNotificationByCategory($category, $toId, Closure $filterScope = null); /** * Send single notification. @@ -162,9 +162,9 @@ public function sendMultiple(array $info); * Get number of notification * not read. * - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id, Closure $filterScope = null); + public function countNotRead($toId, Closure $filterScope = null); } diff --git a/src/Notifynder/Contracts/NotifynderSender.php b/src/Notifynder/Contracts/NotifynderSender.php index 8db59a5..eaa93dd 100755 --- a/src/Notifynder/Contracts/NotifynderSender.php +++ b/src/Notifynder/Contracts/NotifynderSender.php @@ -51,11 +51,11 @@ public function sendMultiple($info); * Send a group of notifications * at once. * - * @param $group_name + * @param $groupName * @param array $info * @return mixed */ - public function sendGroup($group_name, $info = []); + public function sendGroup($groupName, $info = []); /** * This method allow to Extend diff --git a/src/Notifynder/Groups/GroupCategoryRepository.php b/src/Notifynder/Groups/GroupCategoryRepository.php index 2a81858..ff28556 100755 --- a/src/Notifynder/Groups/GroupCategoryRepository.php +++ b/src/Notifynder/Groups/GroupCategoryRepository.php @@ -36,14 +36,14 @@ public function __construct(NotifynderCategory $notificationCategory, /** * Add a category in a group. * - * @param $group_id - * @param $category_id + * @param $groupId + * @param $categoryId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function addCategoryToGroupById($group_id, $category_id) + public function addCategoryToGroupById($groupId, $categoryId) { - $group = $this->notificationGropup->find($group_id); - $group->categories()->attach($category_id); + $group = $this->notificationGropup->find($groupId); + $group->categories()->attach($categoryId); return $group; } @@ -52,15 +52,15 @@ public function addCategoryToGroupById($group_id, $category_id) * Add a category in a group * by names given. * - * @param $group_name - * @param $category_name + * @param $groupName + * @param $categoryName * @return mixed */ - public function addCategoryToGroupByName($group_name, $category_name) + public function addCategoryToGroupByName($groupName, $categoryName) { - $group = $this->notificationGropup->where('name', $group_name)->first(); + $group = $this->notificationGropup->where('name', $groupName)->first(); - $category = $this->notificationCategory->findByName($category_name); + $category = $this->notificationCategory->findByName($categoryName); $group->categories()->attach($category->id); @@ -71,13 +71,13 @@ public function addCategoryToGroupByName($group_name, $category_name) * Add multiple categories by them names * to a group. * - * @param $group_name + * @param $groupName * @param $names * @return mixed */ - public function addMultipleCategoriesToGroup($group_name, array $names) + public function addMultipleCategoriesToGroup($groupName, array $names) { - $group = $this->notificationGropup->where('name', $group_name)->first(); + $group = $this->notificationGropup->where('name', $groupName)->first(); $categories = $this->notificationCategory->findByNames($names); diff --git a/src/Notifynder/Groups/GroupManager.php b/src/Notifynder/Groups/GroupManager.php index 4af6c9c..c7bebd8 100755 --- a/src/Notifynder/Groups/GroupManager.php +++ b/src/Notifynder/Groups/GroupManager.php @@ -37,13 +37,13 @@ public function __construct(NotifynderGroupDB $groupRepo, /** * Find a group by id. * - * @param $group_id + * @param $groupId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static * @throws \Fenos\Notifynder\Exceptions\NotifynderGroupNotFoundException */ - public function findById($group_id) + public function findById($groupId) { - $group = $this->groupRepo->find($group_id); + $group = $this->groupRepo->find($groupId); if (is_null($group)) { $error = 'Group Not Found'; @@ -56,13 +56,13 @@ public function findById($group_id) /** * Find a group By name. * - * @param $group_name + * @param $groupName * @return mixed * @throws \Fenos\Notifynder\Exceptions\NotifynderGroupNotFoundException */ - public function findByName($group_name) + public function findByName($groupName) { - $group = $this->groupRepo->findByName($group_name); + $group = $this->groupRepo->findByName($groupName); if (is_null($group)) { $error = 'Group Not Found'; @@ -76,26 +76,26 @@ public function findByName($group_name) * Add category to a group * giving the ids of them. * - * @param $gorup_id - * @param $category_id + * @param $groupId + * @param $categoryId * @return mixed */ - public function addCategoryToGroupById($gorup_id, $category_id) + public function addCategoryToGroupById($groupId, $categoryId) { - return $this->groupCategory->addCategoryToGroupById($gorup_id, $category_id); + return $this->groupCategory->addCategoryToGroupById($groupId, $categoryId); } /** * Add category to a group * giving the ids of them. * - * @param $gorup_name - * @param $category_name + * @param $groupName + * @param $categoryName * @return mixed */ - public function addCategoryToGroupByName($gorup_name, $category_name) + public function addCategoryToGroupByName($groupName, $categoryName) { - return $this->groupCategory->addCategoryToGroupByName($gorup_name, $category_name); + return $this->groupCategory->addCategoryToGroupByName($groupName, $categoryName); } /** @@ -110,11 +110,11 @@ public function addMultipleCategoriesToGroup() $args = func_get_args(); // First parameter is the group name - $group_name = array_shift($args); + $groupName = array_shift($args); $names = (is_array($args[0])) ? $args[0] : $args; - return $this->groupCategory->addMultipleCategoriesToGroup($group_name, $names); + return $this->groupCategory->addMultipleCategoriesToGroup($groupName, $names); } /** diff --git a/src/Notifynder/Groups/GroupRepository.php b/src/Notifynder/Groups/GroupRepository.php index 1279434..8419c76 100755 --- a/src/Notifynder/Groups/GroupRepository.php +++ b/src/Notifynder/Groups/GroupRepository.php @@ -27,12 +27,12 @@ public function __construct(NotificationGroup $groupModel) /** * Find a group by ID. * - * @param $group_id + * @param $groupId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function find($group_id) + public function find($groupId) { - return $this->groupModel->find($group_id); + return $this->groupModel->find($groupId); } /** @@ -60,11 +60,11 @@ public function create($name) /** * Delete a group. * - * @param $group_id + * @param $groupId * @return mixed */ - public function delete($group_id) + public function delete($groupId) { - return $this->groupModel->where('id', $group_id)->delete(); + return $this->groupModel->where('id', $groupId)->delete(); } } diff --git a/src/Notifynder/Handler/Dispatcher.php b/src/Notifynder/Handler/Dispatcher.php index 955220f..819abfe 100755 --- a/src/Notifynder/Handler/Dispatcher.php +++ b/src/Notifynder/Handler/Dispatcher.php @@ -44,11 +44,11 @@ public function __construct(LaravelDispatcher $event) * * @param Notifynder $notifynder * @param string $eventName - * @param string $category_name + * @param string $categoryName * @param mixed|null $values * @return mixed|null */ - public function fire(Notifynder $notifynder, $eventName, $category_name = null, $values = []) + public function fire(Notifynder $notifynder, $eventName, $categoryName = null, $values = []) { // Generete the event from the name given $eventName = $this->generateEventName($eventName); @@ -56,7 +56,7 @@ public function fire(Notifynder $notifynder, $eventName, $category_name = null, // Instantiate the Notifynder event Object that will provide // nice way to get your data on the handler. It will be the first // parameter - $event = new NotifynderEvent($eventName, $category_name, $values); + $event = new NotifynderEvent($eventName, $categoryName, $values); // Fire the event given expecting an array of notifications or falsy // value to not send the notification diff --git a/src/Notifynder/Notifications/NotificationManager.php b/src/Notifynder/Notifications/NotificationManager.php index 4a31760..2bb9f6b 100755 --- a/src/Notifynder/Notifications/NotificationManager.php +++ b/src/Notifynder/Notifications/NotificationManager.php @@ -51,13 +51,13 @@ public function entity($name) /** * Find a notification by ID. * - * @param $notification_id + * @param $notificationId * @return NotificationModel|\Illuminate\Database\Eloquent\Model|static * @throws \Fenos\Notifynder\Exceptions\NotificationNotFoundException */ - public function find($notification_id) + public function find($notificationId) { - $notification = $this->notifynderRepo->find($notification_id); + $notification = $this->notifynderRepo->find($notificationId); if (is_null($notification)) { $error = 'Notification Not found'; @@ -71,12 +71,12 @@ public function find($notification_id) * Make read one notification giving * the ID of it. * - * @param $notification_id + * @param $notificationId * @return bool|\Fenos\Notifynder\Models\Notification */ - public function readOne($notification_id) + public function readOne($notificationId) { - $notification = $this->find($notification_id); + $notification = $this->find($notificationId); return $this->notifynderRepo->readOne($notification); } @@ -85,38 +85,38 @@ public function readOne($notification_id) * Read notifications in base the number * Given. * - * @param $to_id + * @param $toId * @param $numbers * @param string $order * @return mixed */ - public function readLimit($to_id, $numbers, $order = 'ASC') + public function readLimit($toId, $numbers, $order = 'ASC') { - return $this->notifynderRepo->readLimit($to_id, $this->entity, $numbers, $order); + return $this->notifynderRepo->readLimit($toId, $this->entity, $numbers, $order); } /** * Read all notification of the * given entity. * - * @param $to_id + * @param $toId * @return Number */ - public function readAll($to_id) + public function readAll($toId) { - return $this->notifynderRepo->readAll($to_id, $this->entity); + return $this->notifynderRepo->readAll($toId, $this->entity); } /** * Delete a notification giving the id * of it. * - * @param $notification_id + * @param $notificationId * @return bool */ - public function delete($notification_id) + public function delete($notificationId) { - return $this->notifynderRepo->delete($notification_id); + return $this->notifynderRepo->delete($notificationId); } /** @@ -124,56 +124,56 @@ public function delete($notification_id) * to the number passing as 2 parameter of * the current user. * - * @param $entity_id + * @param $entityId * @param $number * @param $order * @return mixed */ - public function deleteLimit($entity_id, $number, $order = 'asc') + public function deleteLimit($entityId, $number, $order = 'asc') { - return $this->notifynderRepo->deleteLimit($entity_id, $this->entity, $number, $order); + return $this->notifynderRepo->deleteLimit($entityId, $this->entity, $number, $order); } /** * Delete all notification of a given * Entity. * - * @param $entity_id + * @param $entityId * @return bool */ - public function deleteAll($entity_id) + public function deleteAll($entityId) { - return $this->notifynderRepo->deleteAll($entity_id, $this->entity); + return $this->notifynderRepo->deleteAll($entityId, $this->entity); } /** * Delete All notifications from a * defined category. * - * @param $category_name string + * @param $categoryName string * @param $expired Bool * @return bool */ - public function deleteByCategory($category_name, $expired = false) + public function deleteByCategory($categoryName, $expired = false) { - return $this->notifynderRepo->deleteByCategory($category_name, $expired); + return $this->notifynderRepo->deleteByCategory($categoryName, $expired); } /** * Get notifications not read * of the entity given. * - * @param $to_id + * @param $toId * @param $limit * @param int|null $paginate * @param string $orderDate * @param Closure $filterScope * @return mixed */ - public function getNotRead($to_id, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) + public function getNotRead($toId, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) { $notifications = $this->notifynderRepo->getNotRead( - $to_id, $this->entity, + $toId, $this->entity, $limit, $paginate, $orderDate, $filterScope ); @@ -190,17 +190,17 @@ public function getNotRead($to_id, $limit = null, $paginate = null, $orderDate = /** * Get All notifications. * - * @param $to_id + * @param $toId * @param $limit * @param int|null $paginate * @param string $orderDate * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) + public function getAll($toId, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) { $notifications = $this->notifynderRepo->getAll( - $to_id, $this->entity, + $toId, $this->entity, $limit, $paginate, $orderDate, $filterScope ); @@ -218,13 +218,13 @@ public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'de * Get last notification of the * given entity. * - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id, Closure $filterScope = null) + public function getLastNotification($toId, Closure $filterScope = null) { - return $this->notifynderRepo->getLastNotification($to_id, $this->entity, $filterScope); + return $this->notifynderRepo->getLastNotification($toId, $this->entity, $filterScope); } /** @@ -232,13 +232,13 @@ public function getLastNotification($to_id, Closure $filterScope = null) * given entity of the specific category. * * @param $category - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function getLastNotificationByCategory($category, $to_id, Closure $filterScope = null) + public function getLastNotificationByCategory($category, $toId, Closure $filterScope = null) { - return $this->notifynderRepo->getLastNotificationByCategory($category, $to_id, $this->entity, $filterScope); + return $this->notifynderRepo->getLastNotificationByCategory($category, $toId, $this->entity, $filterScope); } /** @@ -267,12 +267,12 @@ public function sendMultiple(array $info) * Get number of notification * not read. * - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id, Closure $filterScope = null) + public function countNotRead($toId, Closure $filterScope = null) { - return $this->notifynderRepo->countNotRead($to_id, $this->entity); + return $this->notifynderRepo->countNotRead($toId, $this->entity); } } diff --git a/src/Notifynder/Senders/SenderManager.php b/src/Notifynder/Senders/SenderManager.php index f73ed7a..5dfe131 100755 --- a/src/Notifynder/Senders/SenderManager.php +++ b/src/Notifynder/Senders/SenderManager.php @@ -107,14 +107,14 @@ public function sendMultiple($info) * Send a group of notifications * at once. * - * @param $group_name + * @param $groupName * @param array $info * @return mixed */ - public function sendGroup($group_name, $info = []) + public function sendGroup($groupName, $info = []) { return $this->senderFactory->sendGroup( - $group_name, + $groupName, $info )->send($this->storeNotification); } From 5fefebc8b6927f4f7b2286d4bb940c05c6fcf7b5 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 14:09:02 +0200 Subject: [PATCH 073/210] use not used $filterScope --- src/Notifynder/Notifications/NotificationManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Notifications/NotificationManager.php b/src/Notifynder/Notifications/NotificationManager.php index 2bb9f6b..96f5af6 100755 --- a/src/Notifynder/Notifications/NotificationManager.php +++ b/src/Notifynder/Notifications/NotificationManager.php @@ -273,6 +273,6 @@ public function sendMultiple(array $info) */ public function countNotRead($toId, Closure $filterScope = null) { - return $this->notifynderRepo->countNotRead($toId, $this->entity); + return $this->notifynderRepo->countNotRead($toId, $this->entity, $filterScope); } } From e4924ee463ffe8dc72d7e75b3def54f12ddb7c2a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 14:13:38 +0200 Subject: [PATCH 074/210] disable boolean argument flag check --- .codeclimate.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.codeclimate.yml b/.codeclimate.yml index 83f35da..6625bbc 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -12,6 +12,8 @@ engines: checks: CleanCode/StaticAccess: enabled: false + CleanCode/BooleanArgumentFlag: + enabled: false Design/TooManyPublicMethods: enabled: false Design/CouplingBetweenObjects: From c491c28668fd461fcd797b5370907f66b1307495 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 16:24:53 +0200 Subject: [PATCH 075/210] fix code climate issues --- src/Notifynder/Categories/CategoryManager.php | 6 +- .../Categories/CategoryRepository.php | 6 +- src/Notifynder/Contracts/CategoryDB.php | 4 +- .../Contracts/NotifynderCategory.php | 4 +- src/Notifynder/Notifynder.php | 40 ++++++------- src/Notifynder/NotifynderManager.php | 60 +++++++++---------- 6 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/Notifynder/Categories/CategoryManager.php b/src/Notifynder/Categories/CategoryManager.php index de01646..7ad5848 100755 --- a/src/Notifynder/Categories/CategoryManager.php +++ b/src/Notifynder/Categories/CategoryManager.php @@ -123,11 +123,11 @@ public function deleteByName($name) * Update a category. * * @param array $data - * @param $id + * @param $categoryId * @return mixed */ - public function update(array $data, $id) + public function update(array $data, $categoryId) { - return $this->categoryRepo->update($data, $id); + return $this->categoryRepo->update($data, $categoryId); } } diff --git a/src/Notifynder/Categories/CategoryRepository.php b/src/Notifynder/Categories/CategoryRepository.php index da1457f..59e9693 100755 --- a/src/Notifynder/Categories/CategoryRepository.php +++ b/src/Notifynder/Categories/CategoryRepository.php @@ -103,12 +103,12 @@ public function deleteByName($name) * Update a category by id. * * @param array $data - * @param $id + * @param $categoryId * @return mixed */ - public function update(array $data, $id) + public function update(array $data, $categoryId) { - return $this->categoryModel->where('id', $id) + return $this->categoryModel->where('id', $categoryId) ->update($data); } } diff --git a/src/Notifynder/Contracts/CategoryDB.php b/src/Notifynder/Contracts/CategoryDB.php index be421b2..bcbf7e9 100755 --- a/src/Notifynder/Contracts/CategoryDB.php +++ b/src/Notifynder/Contracts/CategoryDB.php @@ -64,8 +64,8 @@ public function deleteByName($name); * Update a category by id. * * @param array $data - * @param $id + * @param $categoryId * @return mixed */ - public function update(array $data, $id); + public function update(array $data, $categoryId); } diff --git a/src/Notifynder/Contracts/NotifynderCategory.php b/src/Notifynder/Contracts/NotifynderCategory.php index 8b9fa33..eba0fa3 100755 --- a/src/Notifynder/Contracts/NotifynderCategory.php +++ b/src/Notifynder/Contracts/NotifynderCategory.php @@ -69,8 +69,8 @@ public function deleteByName($name); * Update a category. * * @param array $data - * @param $id + * @param $categoryId * @return mixed */ - public function update(array $data, $id); + public function update(array $data, $categoryId); } diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php index e41d105..7219a97 100755 --- a/src/Notifynder/Notifynder.php +++ b/src/Notifynder/Notifynder.php @@ -48,10 +48,10 @@ public function addCategory($name, $text); * Update a category. * * @param array $updates - * @param $id + * @param $categoryId * @return mixed */ - public function updateCategory(array $updates, $id); + public function updateCategory(array $updates, $categoryId); /** * Send notifications @@ -108,21 +108,21 @@ public function readOne($notification_id); * Read notification in base the number * Given. * - * @param $to_id + * @param $toId * @param $numbers * @param string $order * @return mixed */ - public function readLimit($to_id, $numbers, $order = 'ASC'); + public function readLimit($toId, $numbers, $order = 'ASC'); /** * Read all notifications of the given * entity. * - * @param $to_id + * @param $toId * @return int */ - public function readAll($to_id); + public function readAll($toId); /** * Delete a single notification. @@ -136,21 +136,21 @@ public function delete($notification_id); * Delete number of notifications * secified of the given entity. * - * @param $to_id + * @param $toId * @param $number * @param string $order * @return mixed */ - public function deleteLimit($to_id, $number, $order = 'ASC'); + public function deleteLimit($toId, $number, $order = 'ASC'); /** * Delete all notifications * of the the given entity. * - * @param $to_id + * @param $toId * @return bool */ - public function deleteAll($to_id); + public function deleteAll($toId); /** * Delete All notifications from a @@ -166,37 +166,37 @@ public function deleteByCategory($category_name, $expired = false); * Get Notifications not read * of the given entity. * - * @param $to_id + * @param $toId * @param null $limit * @param bool $paginate * @param string $order * @param Closure $filterScope * @return mixed */ - public function getNotRead($to_id, $limit = null, $paginate = false, $order = 'desc', Closure $filterScope = null); + public function getNotRead($toId, $limit = null, $paginate = false, $order = 'desc', Closure $filterScope = null); /** * Get all notifications of the * given entity. * - * @param $to_id + * @param $toId * @param null $limit * @param bool $paginate * @param string $order * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $limit = null, $paginate = false, $order = 'desc', Closure $filterScope = null); + public function getAll($toId, $limit = null, $paginate = false, $order = 'desc', Closure $filterScope = null); /** * Get number of notification not read * of the given entity. * - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id, Closure $filterScope = null); + public function countNotRead($toId, Closure $filterScope = null); /** * Find Notification by ID. @@ -211,12 +211,12 @@ public function findNotificationById($notification_id); * entity, second parameter can filter by * category. * - * @param $to_id + * @param $toId * @param null $category * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id, $category = null, Closure $filterScope = null); + public function getLastNotification($toId, $category = null, Closure $filterScope = null); /** * Add category to a group @@ -252,11 +252,11 @@ public function addCategoriesToGroup(); * of logic. * * @param string $key - * @param string $category_name + * @param string $categoryName * @param mixed|null $values * @return mixed|null */ - public function fire($key, $category_name, $values = []); + public function fire($key, $categoryName, $values = []); /** * Associate events to categories. diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index 78838a6..1059d80 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -170,9 +170,9 @@ public function addCategory($name, $text) * @param $id * @return mixed */ - public function updateCategory(array $updates, $id) + public function updateCategory(array $updates, $categoryId) { - return $this->notifynderCategory->update($updates, $id); + return $this->notifynderCategory->update($updates, $categoryId); } /** @@ -278,30 +278,30 @@ public function readOne($notification_id) * Read notification in base the number * Given. * - * @param $to_id + * @param $toId * @param $numbers * @param string $order * @return mixed */ - public function readLimit($to_id, $numbers, $order = 'ASC') + public function readLimit($toId, $numbers, $order = 'ASC') { $notification = $this->notification->entity($this->entity); - return $notification->readLimit($to_id, $numbers, $order); + return $notification->readLimit($toId, $numbers, $order); } /** * Read all notifications of the given * entity. * - * @param $to_id + * @param $toId * @return Number */ - public function readAll($to_id) + public function readAll($toId) { $notifications = $this->notification->entity($this->entity); - return $notifications->readAll($to_id); + return $notifications->readAll($toId); } /** @@ -319,30 +319,30 @@ public function delete($notification_id) * Delete number of notifications * secified of the given entity. * - * @param $to_id + * @param $toId * @param $number * @param string $order * @return mixed */ - public function deleteLimit($to_id, $number, $order = 'ASC') + public function deleteLimit($toId, $number, $order = 'ASC') { $notifications = $this->notification->entity($this->entity); - return $notifications->deleteLimit($to_id, $number, $order); + return $notifications->deleteLimit($toId, $number, $order); } /** * Delete all notifications * of the the given entity. * - * @param $to_id + * @param $toId * @return bool */ - public function deleteAll($to_id) + public function deleteAll($toId) { $notifications = $this->notification->entity($this->entity); - return $notifications->deleteAll($to_id); + return $notifications->deleteAll($toId); } /** @@ -362,51 +362,51 @@ public function deleteByCategory($category_name, $expired = false) * Get Notifications not read * of the given entity. * - * @param $to_id + * @param $toId * @param null $limit * @param null|int $paginate * @param string $order * @param Closure $filterScope * @return mixed */ - public function getNotRead($to_id, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) + public function getNotRead($toId, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); - return $notifications->getNotRead($to_id, $limit, $paginate, $order, $filterScope); + return $notifications->getNotRead($toId, $limit, $paginate, $order, $filterScope); } /** * Get all notifications of the * given entity. * - * @param $to_id + * @param $toId * @param null $limit * @param int|null $paginate * @param string $order * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) + public function getAll($toId, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); - return $notifications->getAll($to_id, $limit, $paginate, $order, $filterScope); + return $notifications->getAll($toId, $limit, $paginate, $order, $filterScope); } /** * Get number of notification not read * of the given entity. * - * @param $to_id + * @param $toId * @param Closure $filterScope * @return mixed */ - public function countNotRead($to_id, Closure $filterScope = null) + public function countNotRead($toId, Closure $filterScope = null) { $notifications = $this->notification->entity($this->entity); - return $notifications->countNotRead($to_id, $filterScope); + return $notifications->countNotRead($toId, $filterScope); } /** @@ -425,20 +425,20 @@ public function findNotificationById($notification_id) * entity, second parameter can filter by * category. * - * @param $to_id + * @param $toId * @param null $category * @param Closure $filterScope * @return mixed */ - public function getLastNotification($to_id, $category = null, Closure $filterScope = null) + public function getLastNotification($toId, $category = null, Closure $filterScope = null) { $notification = $this->notification->entity($this->entity); if (is_null($category)) { - return $notification->getLastNotification($to_id, $filterScope); + return $notification->getLastNotification($toId, $filterScope); } - return $notification->getLastNotificationByCategory($category, $to_id, $filterScope); + return $notification->getLastNotificationByCategory($category, $toId, $filterScope); } /** @@ -484,14 +484,14 @@ public function addCategoriesToGroup() * of logic. * * @param string $key - * @param string $category_name + * @param string $categoryName * @param mixed|null $values * @return mixed|null */ - public function fire($key, $category_name, $values = []) + public function fire($key, $categoryName, $values = []) { return $this->notifynderDispatcher->sendWith($this->eventSender) - ->fire($this, $key, $category_name, $values); + ->fire($this, $key, $categoryName, $values); } /** From ec19f560d18ebab23757e2f47977352fde369d0a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 16:28:58 +0200 Subject: [PATCH 076/210] fix code climate issues - camelCase --- src/Notifynder/Notifynder.php | 16 +++++----- src/Notifynder/NotifynderManager.php | 44 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php index 7219a97..de7f058 100755 --- a/src/Notifynder/Notifynder.php +++ b/src/Notifynder/Notifynder.php @@ -90,19 +90,19 @@ public function sendMultiple($info = []); /** * Send a group of notifications. * - * @param $group_name + * @param $groupName * @param $info * @return mixed */ - public function sendGroup($group_name, $info = []); + public function sendGroup($groupName, $info = []); /** * Read one notification. * - * @param $notification_id + * @param $notificationId * @return bool|Models\Notification */ - public function readOne($notification_id); + public function readOne($notificationId); /** * Read notification in base the number @@ -127,10 +127,10 @@ public function readAll($toId); /** * Delete a single notification. * - * @param $notification_id + * @param $notificationId * @return bool */ - public function delete($notification_id); + public function delete($notificationId); /** * Delete number of notifications @@ -201,10 +201,10 @@ public function countNotRead($toId, Closure $filterScope = null); /** * Find Notification by ID. * - * @param $notification_id + * @param $notificationId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function findNotificationById($notification_id); + public function findNotificationById($notificationId); /** * Get last notification of the given diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index 1059d80..e2ee1ba 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -248,15 +248,15 @@ public function sendMultiple($info = []) /** * Send a group of notifications. * - * @param $group_name + * @param $groupName * @param $info * @return mixed */ - public function sendGroup($group_name, $info = []) + public function sendGroup($groupName, $info = []) { $info = (count($info) > 0) ? $info : $this->toArray(); - $notificationsSent = $this->notifynderSender->sendGroup($this, $group_name, $info); + $notificationsSent = $this->notifynderSender->sendGroup($this, $groupName, $info); $this->refresh(); @@ -266,12 +266,12 @@ public function sendGroup($group_name, $info = []) /** * Read one notification. * - * @param $notification_id + * @param $notificationId * @return bool|Models\Notification */ - public function readOne($notification_id) + public function readOne($notificationId) { - return $this->notification->readOne($notification_id); + return $this->notification->readOne($notificationId); } /** @@ -307,12 +307,12 @@ public function readAll($toId) /** * Delete a single notification. * - * @param $notification_id + * @param $notificationId * @return bool */ - public function delete($notification_id) + public function delete($notificationId) { - return $this->notification->delete($notification_id); + return $this->notification->delete($notificationId); } /** @@ -349,13 +349,13 @@ public function deleteAll($toId) * Delete All notifications from a * defined category. * - * @param $category_name string + * @param $categoryName string * @param $expired Bool * @return bool */ - public function deleteByCategory($category_name, $expired = false) + public function deleteByCategory($categoryName, $expired = false) { - return $this->notification->deleteByCategory($category_name, $expired); + return $this->notification->deleteByCategory($categoryName, $expired); } /** @@ -412,12 +412,12 @@ public function countNotRead($toId, Closure $filterScope = null) /** * Find Notification by ID. * - * @param $notification_id + * @param $notificationId * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ - public function findNotificationById($notification_id) + public function findNotificationById($notificationId) { - return $this->notification->find($notification_id); + return $this->notification->find($notificationId); } /** @@ -446,25 +446,25 @@ public function getLastNotification($toId, $category = null, Closure $filterScop * giving the names of them. * * @param $gorup_name - * @param $category_name + * @param $categoryName * @return mixed */ - public function addCategoryToGroupByName($gorup_name, $category_name) + public function addCategoryToGroupByName($gorup_name, $categoryName) { - return $this->notifynderGroup->addCategoryToGroupByName($gorup_name, $category_name); + return $this->notifynderGroup->addCategoryToGroupByName($gorup_name, $categoryName); } /** * Add category to a group * giving the ids of them. * - * @param $gorup_id - * @param $category_id + * @param $groupId + * @param $categoryId * @return mixed */ - public function addCategoryToGroupById($gorup_id, $category_id) + public function addCategoryToGroupById($groupId, $categoryId) { - return $this->notifynderGroup->addCategoryToGroupById($gorup_id, $category_id); + return $this->notifynderGroup->addCategoryToGroupById($groupId, $categoryId); } /** From 58b3d4003b9c618115de27c3084d30dc086f4432 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 16:32:21 +0200 Subject: [PATCH 077/210] fix code climate issues - camelCase --- src/Notifynder/Notifynder.php | 16 ++++++++-------- src/Notifynder/NotifynderManager.php | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php index de7f058..ba85b2f 100755 --- a/src/Notifynder/Notifynder.php +++ b/src/Notifynder/Notifynder.php @@ -156,11 +156,11 @@ public function deleteAll($toId); * Delete All notifications from a * defined category. * - * @param $category_name string + * @param $categoryName string * @param $expired Bool * @return bool */ - public function deleteByCategory($category_name, $expired = false); + public function deleteByCategory($categoryName, $expired = false); /** * Get Notifications not read @@ -222,21 +222,21 @@ public function getLastNotification($toId, $category = null, Closure $filterScop * Add category to a group * giving the names of them. * - * @param $gorup_name - * @param $category_name + * @param $groupName + * @param $categoryName * @return mixed */ - public function addCategoryToGroupByName($gorup_name, $category_name); + public function addCategoryToGroupByName($groupName, $categoryName); /** * Add category to a group * giving the ids of them. * - * @param $gorup_id - * @param $category_id + * @param $groupId + * @param $categoryId * @return mixed */ - public function addCategoryToGroupById($gorup_id, $category_id); + public function addCategoryToGroupById($groupId, $categoryId); /** * Add categories to a group having as first parameter diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index e2ee1ba..f131880 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -445,13 +445,13 @@ public function getLastNotification($toId, $category = null, Closure $filterScop * Add category to a group * giving the names of them. * - * @param $gorup_name + * @param $groupName * @param $categoryName * @return mixed */ - public function addCategoryToGroupByName($gorup_name, $categoryName) + public function addCategoryToGroupByName($groupName, $categoryName) { - return $this->notifynderGroup->addCategoryToGroupByName($gorup_name, $categoryName); + return $this->notifynderGroup->addCategoryToGroupByName($groupName, $categoryName); } /** From 60eb47ce890e71f6af73485a51001aa5a384256e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 17 May 2016 17:23:47 +0200 Subject: [PATCH 078/210] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 747a8d6..aa7bafa 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Community: **[Slack](https://notifynder.slack.com)** | **[Signup](https://notify Add it on your `composer.json` - "fenos/notifynder": "3.1.*" + "fenos/notifynder": "^3.2" and run From 1e3d7e070f8b35e9230fff19934698eea1552e9f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 18 May 2016 12:19:22 +0200 Subject: [PATCH 079/210] Issue #126 fix the problem with setters/getters array/json and so on in extras --- src/Notifynder/Models/Notification.php | 9 ++--- src/Notifynder/Notifications/ExtraParams.php | 22 ++++++++++-- .../Notifications/NotificationTest.php | 34 +++++++++++++++++++ .../NotificationRepositoryDBTest.php | 4 ++- 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index b4e6db2..5f41308 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -153,17 +153,14 @@ public function getNotifyBodyAttribute() /** * @param $value - * @return mixed|string + * @return \Fenos\Notifynder\Notifications\ExtraParams */ public function getExtraAttribute($value) { - if (is_array($value)) { + if(!empty($value)) { return new ExtraParams($value); - } elseif (is_string($value)) { - return new ExtraParams(json_decode($value)); - } else { - return new ExtraParams([]); } + return new ExtraParams([]); } /** diff --git a/src/Notifynder/Notifications/ExtraParams.php b/src/Notifynder/Notifications/ExtraParams.php index b40b39c..38b16f4 100644 --- a/src/Notifynder/Notifications/ExtraParams.php +++ b/src/Notifynder/Notifications/ExtraParams.php @@ -3,12 +3,15 @@ namespace Fenos\Notifynder\Notifications; use ArrayAccess; +use JsonSerializable; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Contracts\Support\Jsonable; use stdClass; /** * Class Jsonable. */ -class ExtraParams implements ArrayAccess +class ExtraParams implements ArrayAccess, Arrayable, Jsonable, JsonSerializable { /** * @var array|stdClass|string @@ -30,11 +33,24 @@ public function __construct($extraParams) } /** + * Convert the model instance to JSON. + * + * @param int $options * @return string */ - public function toJson() + public function toJson($options = 0) + { + return json_encode($this->jsonSerialize(), $options); + } + + /** + * Convert the object into something JSON serializable. + * + * @return array + */ + public function jsonSerialize() { - return json_encode($this->extraParams); + return $this->toArray(); } /** diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index fc0981b..0549f95 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -161,4 +161,38 @@ public function it_retrieve_notification_with_parsed_body_and_multi_dots_with_ob $bodyParsed = 'parse this Amazing value from User#1 (John Doe)'; $this->assertEquals($bodyParsed, $notifications[0]->text); } + + /** @test */ + public function it_retrieve_notification_with_extraparams_extra() + { + $extraValues = json_encode(['look' => 'Amazing']); + $category = $this->createCategory(['text' => 'parse this {extra.look} value']); + + $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); + + $notifications = $this->notification->getNotRead($notification->to->id); + $extra = $notifications->first()->extra; + + $this->assertCount(1, $notifications); + $this->assertInstanceOf(\Fenos\Notifynder\Notifications\ExtraParams::class, $extra); + $this->assertEquals('Amazing', $extra->look); + } + + /** @test */ + public function it_retrieve_notifications_toarray() + { + $extraValues = json_encode(['look' => 'Amazing']); + $category = $this->createCategory(['text' => 'parse this {extra.look} value']); + + $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); + + $notifications = $this->notification->getNotRead($notification->to->id)->toArray(); + + $this->assertInternalType('array', $notifications); + $this->assertCount(1, $notifications); + $this->assertInternalType('array', $notifications[0]); + $this->assertArrayHasKey('extra', $notifications[0]); + $this->assertInternalType('array', $notifications[0]['extra']); + $this->assertEquals('Amazing', $notifications[0]['extra']['look']); + } } diff --git a/tests/integration/Repositories/NotificationRepositoryDBTest.php b/tests/integration/Repositories/NotificationRepositoryDBTest.php index ab01425..d54b50b 100755 --- a/tests/integration/Repositories/NotificationRepositoryDBTest.php +++ b/tests/integration/Repositories/NotificationRepositoryDBTest.php @@ -274,6 +274,8 @@ public function it_get_the_last_notificiation_sent_by_category() */ protected function buildNotification(array $data = []) { - return Factory::build(Notification::class, $data)->toArray(); + $notification = Factory::build(Notification::class, $data)->toArray(); + $notification['extra'] = json_encode($notification['extra']); + return $notification; } } From 09aa463a403e30fb40732b553f204ccb7de73a8a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 18 May 2016 06:19:38 -0400 Subject: [PATCH 080/210] Applied fixes from StyleCI --- src/Notifynder/Models/Notification.php | 3 ++- .../integration/Repositories/NotificationRepositoryDBTest.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 5f41308..44db756 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -157,9 +157,10 @@ public function getNotifyBodyAttribute() */ public function getExtraAttribute($value) { - if(!empty($value)) { + if (! empty($value)) { return new ExtraParams($value); } + return new ExtraParams([]); } diff --git a/tests/integration/Repositories/NotificationRepositoryDBTest.php b/tests/integration/Repositories/NotificationRepositoryDBTest.php index d54b50b..316d894 100755 --- a/tests/integration/Repositories/NotificationRepositoryDBTest.php +++ b/tests/integration/Repositories/NotificationRepositoryDBTest.php @@ -276,6 +276,7 @@ protected function buildNotification(array $data = []) { $notification = Factory::build(Notification::class, $data)->toArray(); $notification['extra'] = json_encode($notification['extra']); + return $notification; } } From ba02c8cf1247563ea0d061571bf08760d2a7ac80 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 18 May 2016 17:03:29 +0200 Subject: [PATCH 081/210] Issue #129 The migration should be published and not just existing ... --- src/Notifynder/NotifynderServiceProvider.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index ff2bb0a..a5c3071 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -298,6 +298,9 @@ protected function migration() if (! class_exists('AlterCategoryNameToUnique')) { $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique'); } + if (! class_exists('MakeUrlNullable')) { + $this->publishMigration('2016_04_19_200827_make_url_nullable'); + } } /** From d327c1dadf1d772c57e2ba4df9c6ddbdda6618fc Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 18 May 2016 17:07:16 +0200 Subject: [PATCH 082/210] better naming for migration to prevent conflicts --- src/Notifynder/NotifynderServiceProvider.php | 4 ++-- ...p => 2016_04_19_200827_make_notification_url_nullable.php} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/migrations/{2016_04_19_200827_make_url_nullable.php => 2016_04_19_200827_make_notification_url_nullable.php} (91%) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index a5c3071..45aec91 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -298,8 +298,8 @@ protected function migration() if (! class_exists('AlterCategoryNameToUnique')) { $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique'); } - if (! class_exists('MakeUrlNullable')) { - $this->publishMigration('2016_04_19_200827_make_url_nullable'); + if (! class_exists('MakeNotificationUrlNullable')) { + $this->publishMigration('2016_04_19_200827_make_notification_url_nullable'); } } diff --git a/src/migrations/2016_04_19_200827_make_url_nullable.php b/src/migrations/2016_04_19_200827_make_notification_url_nullable.php similarity index 91% rename from src/migrations/2016_04_19_200827_make_url_nullable.php rename to src/migrations/2016_04_19_200827_make_notification_url_nullable.php index 58340dc..209686d 100644 --- a/src/migrations/2016_04_19_200827_make_url_nullable.php +++ b/src/migrations/2016_04_19_200827_make_notification_url_nullable.php @@ -3,7 +3,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class MakeUrlNullable extends Migration +class MakeNotificationUrlNullable extends Migration { /** * Run the migrations. From a1fee68a577394daee6da5782bd8b87099915149 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 19 May 2016 17:05:31 +0200 Subject: [PATCH 083/210] Issue #103 add stack_id to identify a stack of notifications --- src/Notifynder/Models/Notification.php | 12 +++++-- .../Notifications/NotificationRepository.php | 17 +++++++--- src/Notifynder/NotifynderServiceProvider.php | 3 ++ ...9_144531_add_stack_id_to_notifications.php | 31 +++++++++++++++++++ .../Notifications/NotificationTest.php | 4 +-- tests/integration/Senders/SendersTest.php | 14 +++++++-- 6 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 src/migrations/2016_05_19_144531_add_stack_id_to_notifications.php diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 44db756..fba636e 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -33,8 +33,16 @@ class Notification extends Model * @var array */ protected $fillable = [ - 'to_id', 'to_type', 'from_id', 'from_type', - 'category_id', 'read', 'url', 'extra', 'expire_time', + 'to_id', + 'to_type', + 'from_id', + 'from_type', + 'category_id', + 'read', + 'url', + 'extra', + 'expire_time', + 'stack_id', ]; /** diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index 88299f8..3916a43 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -63,14 +63,23 @@ public function storeSingle(array $info) * Save multiple notifications sent * at once. * - * @param array $info + * @param array $notifications * @return mixed */ - public function storeMultiple(array $info) + public function storeMultiple(array $notifications) { - return $this->db->table( + $this->db->beginTransaction(); + $stackId = $this->db->table( + $this->notification->getTable() + )->max('stack_id') + 1; + foreach($notifications as $key => $notification) { + $notifications[$key]['stack_id'] = $stackId; + } + $insert = $this->db->table( $this->notification->getTable() - )->insert($info); + )->insert($notifications); + $this->db->commit(); + return $insert; } /** diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 45aec91..a638d0a 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -301,6 +301,9 @@ protected function migration() if (! class_exists('MakeNotificationUrlNullable')) { $this->publishMigration('2016_04_19_200827_make_notification_url_nullable'); } + if (! class_exists('AddStackIdToNotifications')) { + $this->publishMigration('2016_05_19_144531_add_stack_id_to_notifications'); + } } /** diff --git a/src/migrations/2016_05_19_144531_add_stack_id_to_notifications.php b/src/migrations/2016_05_19_144531_add_stack_id_to_notifications.php new file mode 100644 index 0000000..0d0a413 --- /dev/null +++ b/src/migrations/2016_05_19_144531_add_stack_id_to_notifications.php @@ -0,0 +1,31 @@ +integer('stack_id')->unsigned()->nullable()->after('expire_time'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('notifications', function (Blueprint $table) { + $table->dropColumn('stack_id'); + }); + } +} diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 0549f95..825f79a 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -120,9 +120,7 @@ public function it_will_check_the_fillable_fields_options_are_allowing_to_save_t $model = app(\Fenos\Notifynder\Models\Notification::class); $fillable = [ - 'to_id', 'to_type', 'from_id', 'from_type', - 'category_id', 'read', 'url', 'extra', 'expire_time', - 'icon_type', + 'to_id', 'to_type', 'from_id', 'from_type', 'category_id', 'read', 'url', 'extra', 'expire_time', 'stack_id', 'icon_type', ]; $this->assertEquals($fillable, $model->getFillable()); diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 3a1aac3..cee3223 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -59,8 +59,13 @@ public function it_send_now_a_single_notification() // Send Single $this->senders->sendNow($singleNotification); + + $notifications = Notification::all(); + $stackIds = $notifications->pluck('stack_id')->unique()->toArray(); - $this->assertCount(1, Notification::all()); + $this->assertCount(1, $notifications); + $this->assertCount(1, $stackIds); + $this->assertEquals([null], $stackIds); } /** @test */ @@ -84,7 +89,12 @@ function (NotifynderBuilder $builder, $value) use ($category_name) { // Send Single $this->senders->sendNow($sendMultiple); - $this->assertCount(2, Notification::all()); + $notifications = Notification::all(); + $stackIds = $notifications->pluck('stack_id')->unique()->toArray(); + + $this->assertCount(2, $notifications); + $this->assertCount(1, $stackIds); + $this->assertEquals([1], $stackIds); } /** @test */ From a3cf694c86b6b170bbd10faba7cff4335abc6531 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 19 May 2016 11:06:36 -0400 Subject: [PATCH 084/210] Applied fixes from StyleCI --- src/Notifynder/Notifications/NotificationRepository.php | 3 ++- tests/integration/Senders/SendersTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index 3916a43..344cdf3 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -72,13 +72,14 @@ public function storeMultiple(array $notifications) $stackId = $this->db->table( $this->notification->getTable() )->max('stack_id') + 1; - foreach($notifications as $key => $notification) { + foreach ($notifications as $key => $notification) { $notifications[$key]['stack_id'] = $stackId; } $insert = $this->db->table( $this->notification->getTable() )->insert($notifications); $this->db->commit(); + return $insert; } diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index cee3223..b99351a 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -59,7 +59,7 @@ public function it_send_now_a_single_notification() // Send Single $this->senders->sendNow($singleNotification); - + $notifications = Notification::all(); $stackIds = $notifications->pluck('stack_id')->unique()->toArray(); From 78312c64d68e8904c1a1fd989d04ee4ce1b693aa Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 14:44:28 +0200 Subject: [PATCH 085/210] fix pluck in older laravel versions --- tests/integration/Senders/SendersTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index b99351a..f19fc1c 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -61,7 +61,7 @@ public function it_send_now_a_single_notification() $this->senders->sendNow($singleNotification); $notifications = Notification::all(); - $stackIds = $notifications->pluck('stack_id')->unique()->toArray(); + $stackIds = array_unique($notifications->lists('stack_id')); $this->assertCount(1, $notifications); $this->assertCount(1, $stackIds); @@ -90,7 +90,7 @@ function (NotifynderBuilder $builder, $value) use ($category_name) { $this->senders->sendNow($sendMultiple); $notifications = Notification::all(); - $stackIds = $notifications->pluck('stack_id')->unique()->toArray(); + $stackIds = array_unique($notifications->lists('stack_id')); $this->assertCount(2, $notifications); $this->assertCount(1, $stackIds); From bb3768549505f32a5cdd5300b8e2a1d0047d22fe Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 14:57:24 +0200 Subject: [PATCH 086/210] fix pluck in older laravel versions --- tests/integration/Senders/SendersTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index f19fc1c..ecbe38e 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -61,7 +61,7 @@ public function it_send_now_a_single_notification() $this->senders->sendNow($singleNotification); $notifications = Notification::all(); - $stackIds = array_unique($notifications->lists('stack_id')); + $stackIds = array_unique((array) $notifications->lists('stack_id')); $this->assertCount(1, $notifications); $this->assertCount(1, $stackIds); @@ -90,7 +90,7 @@ function (NotifynderBuilder $builder, $value) use ($category_name) { $this->senders->sendNow($sendMultiple); $notifications = Notification::all(); - $stackIds = array_unique($notifications->lists('stack_id')); + $stackIds = array_unique((array) $notifications->lists('stack_id')); $this->assertCount(2, $notifications); $this->assertCount(1, $stackIds); From 6eeaad7487b5abe08f5cedccd9cbc901afbec13a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 16:10:48 +0200 Subject: [PATCH 087/210] fix the never ending problem with collection and array return values between laravel versions --- tests/integration/Senders/SendersTest.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index ecbe38e..53b67a6 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -60,10 +60,13 @@ public function it_send_now_a_single_notification() // Send Single $this->senders->sendNow($singleNotification); - $notifications = Notification::all(); - $stackIds = array_unique((array) $notifications->lists('stack_id')); + $stackIds = Notification::lists('stack_id'); + if($stackIds instanceof \Illuminate\Support\Collection) { + $stackIds = $stackIds->toArray(); + } + $stackIds = array_unique($stackIds); - $this->assertCount(1, $notifications); + $this->assertCount(1, Notification::all()); $this->assertCount(1, $stackIds); $this->assertEquals([null], $stackIds); } @@ -89,10 +92,13 @@ function (NotifynderBuilder $builder, $value) use ($category_name) { // Send Single $this->senders->sendNow($sendMultiple); - $notifications = Notification::all(); - $stackIds = array_unique((array) $notifications->lists('stack_id')); + $stackIds = Notification::lists('stack_id'); + if($stackIds instanceof \Illuminate\Support\Collection) { + $stackIds = $stackIds->toArray(); + } + $stackIds = array_unique($stackIds); - $this->assertCount(2, $notifications); + $this->assertCount(2, Notification::all()); $this->assertCount(1, $stackIds); $this->assertEquals([1], $stackIds); } From 4f181d89b26d27351c9b8d6d3dc7ec4f9d6d6462 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 10:11:06 -0400 Subject: [PATCH 088/210] Applied fixes from StyleCI --- tests/integration/Senders/SendersTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 53b67a6..4ac0617 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -61,7 +61,7 @@ public function it_send_now_a_single_notification() $this->senders->sendNow($singleNotification); $stackIds = Notification::lists('stack_id'); - if($stackIds instanceof \Illuminate\Support\Collection) { + if ($stackIds instanceof \Illuminate\Support\Collection) { $stackIds = $stackIds->toArray(); } $stackIds = array_unique($stackIds); @@ -93,7 +93,7 @@ function (NotifynderBuilder $builder, $value) use ($category_name) { $this->senders->sendNow($sendMultiple); $stackIds = Notification::lists('stack_id'); - if($stackIds instanceof \Illuminate\Support\Collection) { + if ($stackIds instanceof \Illuminate\Support\Collection) { $stackIds = $stackIds->toArray(); } $stackIds = array_unique($stackIds); From a6d9382f39b6e8e779a1a348d98ca30f4f22f7a8 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 16:54:58 +0200 Subject: [PATCH 089/210] fix codeclimate issues --- src/Notifynder/Artisan/CreateCategory.php | 7 +++-- src/Notifynder/Artisan/CreateGroup.php | 6 ++-- src/Notifynder/Artisan/DeleteCategory.php | 6 ++-- src/Notifynder/Builder/BuilderRules.php | 7 ++--- src/Notifynder/Builder/NotifynderBuilder.php | 31 +++++++++---------- src/Notifynder/Categories/CategoryManager.php | 12 +++---- .../Categories/CategoryRepository.php | 8 ++--- src/Notifynder/Contracts/CategoryDB.php | 4 +-- .../Contracts/NotifynderCategory.php | 4 +-- .../Contracts/NotifynderNotification.php | 6 ++-- src/Notifynder/Models/Notification.php | 17 +++++----- src/Notifynder/Senders/SenderFactory.php | 6 ++-- 12 files changed, 55 insertions(+), 59 deletions(-) diff --git a/src/Notifynder/Artisan/CreateCategory.php b/src/Notifynder/Artisan/CreateCategory.php index d3f00e4..d4c01f8 100755 --- a/src/Notifynder/Artisan/CreateCategory.php +++ b/src/Notifynder/Artisan/CreateCategory.php @@ -52,11 +52,12 @@ public function fire() $createCategory = $this->notifynderCategory->add($name, $text); - if ($createCategory) { - $this->info("Category $createCategory->name has been created"); - } else { + if (!$createCategory) { $this->error('The category has been not created'); + return false; } + + $this->info("Category $createCategory->name has been created"); } /** diff --git a/src/Notifynder/Artisan/CreateGroup.php b/src/Notifynder/Artisan/CreateGroup.php index 62ee127..c7e3ccb 100755 --- a/src/Notifynder/Artisan/CreateGroup.php +++ b/src/Notifynder/Artisan/CreateGroup.php @@ -48,11 +48,11 @@ public function fire() { $nameGroup = $this->argument('name'); - if ($this->notifynderGroup->addGroup($nameGroup)) { - $this->info("Group {$nameGroup} has Been created"); - } else { + if (!$this->notifynderGroup->addGroup($nameGroup)) { $this->error('The name must be a string with dots as namespaces'); + return false; } + $this->info("Group {$nameGroup} has Been created"); } /** diff --git a/src/Notifynder/Artisan/DeleteCategory.php b/src/Notifynder/Artisan/DeleteCategory.php index ace2ced..8c077de 100755 --- a/src/Notifynder/Artisan/DeleteCategory.php +++ b/src/Notifynder/Artisan/DeleteCategory.php @@ -54,11 +54,11 @@ public function fire() $delete = $this->notifynderCategory->deleteByName($indentifier); } - if ($delete) { - $this->info('Category has been deleted'); - } else { + if (!$delete) { $this->error('Category Not found'); + return false; } + $this->info('Category has been deleted'); } public function isIntegerValue($indentifier) diff --git a/src/Notifynder/Builder/BuilderRules.php b/src/Notifynder/Builder/BuilderRules.php index 1211b1f..20d0baf 100755 --- a/src/Notifynder/Builder/BuilderRules.php +++ b/src/Notifynder/Builder/BuilderRules.php @@ -47,7 +47,7 @@ protected function isCarbon($value) return true; } - throw new InvalidArgumentException("The value Passed has to be an instance of Carbon\Carbon"); + throw new InvalidArgumentException("The value Passed has to be an instance of Carbon\\Carbon"); } /** @@ -72,10 +72,9 @@ protected function isNumeric($value) */ public function getRequiredFields() { + $customRequiredFields = []; if (property_exists($this, 'config') && $this->config instanceof Repository) { - $customRequiredFields = $this->config->get('notifynder.additional_fields.required'); - } else { - $customRequiredFields = []; + $customRequiredFields = $this->config->get('notifynder.additional_fields.required', []); } return array_unique($this->requiredFields + $customRequiredFields); diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index e609f74..a8631eb 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -181,26 +181,25 @@ public function raw(Closure $closure) */ public function loop($dataToIterate, Closure $builder) { - if ($this->isIterable($dataToIterate)) { - if (count($dataToIterate) > 0) { - $notifications = []; + if (!$this->isIterable($dataToIterate)) { + throw new EntityNotIterableException('The data passed must be itarable'); + } + if (count($dataToIterate) <= 0) { + throw new IterableIsEmptyException('The Iterable passed must contain at least one element'); + } + + $notifications = []; - $newBuilder = new self($this->notifynderCategory); + $newBuilder = new self($this->notifynderCategory); - foreach ($dataToIterate as $key => $data) { - $builder($newBuilder, $data, $key); - $notifications[] = $newBuilder->toArray(); - } + foreach ($dataToIterate as $key => $data) { + $builder($newBuilder, $data, $key); + $notifications[] = $newBuilder->toArray(); + } - $this->notifications = $notifications; + $this->notifications = $notifications; - return $this; - } else { - throw new IterableIsEmptyException('The Iterable passed must contain at least one element'); - } - } else { - throw new EntityNotIterableException('The data passed must be itarable'); - } + return $this; } /** diff --git a/src/Notifynder/Categories/CategoryManager.php b/src/Notifynder/Categories/CategoryManager.php index 7ad5848..1f78f8e 100755 --- a/src/Notifynder/Categories/CategoryManager.php +++ b/src/Notifynder/Categories/CategoryManager.php @@ -69,13 +69,13 @@ public function findByNames(array $name) /** * Find a category by id. * - * @param $id + * @param $categoryId * @throws CategoryNotFoundException * @return mixed */ - public function find($id) + public function find($categoryId) { - $category = $this->categoryRepo->find($id); + $category = $this->categoryRepo->find($categoryId); if (is_null($category)) { $error = 'Category Not Found'; @@ -100,12 +100,12 @@ public function add($name, $text) /** * Delete category by ID. * - * @param $id + * @param $categoryId * @return mixed */ - public function delete($id) + public function delete($categoryId) { - return $this->categoryRepo->delete($id); + return $this->categoryRepo->delete($categoryId); } /** diff --git a/src/Notifynder/Categories/CategoryRepository.php b/src/Notifynder/Categories/CategoryRepository.php index 59e9693..84a9aec 100755 --- a/src/Notifynder/Categories/CategoryRepository.php +++ b/src/Notifynder/Categories/CategoryRepository.php @@ -33,9 +33,9 @@ public function __construct(NotificationCategory $categoryModel) * @param $id * @return mixed */ - public function find($id) + public function find($categoryId) { - return $this->categoryModel->find($id); + return $this->categoryModel->find($categoryId); } /** @@ -81,9 +81,9 @@ public function add($name, $text) * @param $id * @return mixed */ - public function delete($id) + public function delete($categoryId) { - return $this->categoryModel->where('id', $id) + return $this->categoryModel->where('id', $categoryId) ->delete(); } diff --git a/src/Notifynder/Contracts/CategoryDB.php b/src/Notifynder/Contracts/CategoryDB.php index bcbf7e9..5b29863 100755 --- a/src/Notifynder/Contracts/CategoryDB.php +++ b/src/Notifynder/Contracts/CategoryDB.php @@ -16,7 +16,7 @@ interface CategoryDB * @param $id * @return mixed */ - public function find($id); + public function find($categoryId); /** * Find by name. @@ -50,7 +50,7 @@ public function add($name, $text); * @param $id * @return mixed */ - public function delete($id); + public function delete($categoryId); /** * Delete category by name. diff --git a/src/Notifynder/Contracts/NotifynderCategory.php b/src/Notifynder/Contracts/NotifynderCategory.php index eba0fa3..a69d6f8 100755 --- a/src/Notifynder/Contracts/NotifynderCategory.php +++ b/src/Notifynder/Contracts/NotifynderCategory.php @@ -38,7 +38,7 @@ public function findByNames(array $name); * @throws CategoryNotFoundException * @return mixed */ - public function find($id); + public function find($categoryId); /** * Add a category to the DB. @@ -55,7 +55,7 @@ public function add($name, $text); * @param $id * @return mixed */ - public function delete($id); + public function delete($categoryId); /** * Delete category by name. diff --git a/src/Notifynder/Contracts/NotifynderNotification.php b/src/Notifynder/Contracts/NotifynderNotification.php index ecbeb26..4ca2617 100755 --- a/src/Notifynder/Contracts/NotifynderNotification.php +++ b/src/Notifynder/Contracts/NotifynderNotification.php @@ -81,7 +81,7 @@ public function deleteLimit($entityId, $number, $order); * Delete all notification of a given * Entity. * - * @param $entity_id + * @param $entityId * @return bool */ public function deleteAll($entityId); @@ -112,14 +112,14 @@ public function getNotRead($toId, $limit, $paginate, $orderDate = 'desc', Closur /** * Get All notifications. * - * @param $to_id + * @param $toId * @param $limit * @param $paginate * @param string $orderDate * @param Closure $filterScope * @return mixed */ - public function getAll($to_id, $limit, $paginate, $orderDate = 'desc', Closure $filterScope = null); + public function getAll($toId, $limit, $paginate, $orderDate = 'desc', Closure $filterScope = null); /** * Get last notification of the diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index b4e6db2..41f35ca 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -79,9 +79,8 @@ public function from() // polymorphic. if (config('notifynder.polymorphic') == false) { return $this->belongsTo(config('notifynder.model'), 'from_id'); - } else { - return $this->morphTo(); } + return $this->morphTo(); } /** @@ -94,9 +93,8 @@ public function to() // polymorphic. if (config('notifynder.polymorphic') == false) { return $this->belongsTo(config('notifynder.model'), 'to_id'); - } else { - return $this->morphTo(); } + return $this->morphTo(); } /** @@ -125,18 +123,17 @@ public function scopeOnlyExpired($query) * Where Polymorphic. * * @param $query - * @param $id + * @param $toId * @param $type * @return mixed */ - public function scopeWherePolymorphic($query, $id, $type) + public function scopeWherePolymorphic($query, $toId, $type) { if (! $type or config('notifynder.polymorphic') === false) { - return $query->where('to_id', $id); - } else { - return $query->where('to_id', $id) - ->where('to_type', $type); + return $query->where('to_id', $toId); } + return $query->where('to_id', $toId) + ->where('to_type', $type); } /** diff --git a/src/Notifynder/Senders/SenderFactory.php b/src/Notifynder/Senders/SenderFactory.php index cea9329..9518888 100755 --- a/src/Notifynder/Senders/SenderFactory.php +++ b/src/Notifynder/Senders/SenderFactory.php @@ -87,16 +87,16 @@ public function sendMultiple(array $infoNotifications) /** * Get the the send group instance. * - * @param string $group_name + * @param string $groupName * @param array | \Closure $info * @return SendGroup */ - public function sendGroup($group_name, array $info) + public function sendGroup($groupName, array $info) { return new SendGroup( $this->notifynderGroup, $this->notifynderCategory, - $group_name, + $groupName, $info ); } From 8bea5d84358a67cdf9578a7658658d57b875fd37 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 10:55:09 -0400 Subject: [PATCH 090/210] Applied fixes from StyleCI --- src/Notifynder/Artisan/CreateCategory.php | 3 ++- src/Notifynder/Artisan/CreateGroup.php | 3 ++- src/Notifynder/Artisan/DeleteCategory.php | 3 ++- src/Notifynder/Builder/BuilderRules.php | 2 +- src/Notifynder/Builder/NotifynderBuilder.php | 4 ++-- src/Notifynder/Models/Notification.php | 3 +++ 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Notifynder/Artisan/CreateCategory.php b/src/Notifynder/Artisan/CreateCategory.php index d4c01f8..edb504a 100755 --- a/src/Notifynder/Artisan/CreateCategory.php +++ b/src/Notifynder/Artisan/CreateCategory.php @@ -52,8 +52,9 @@ public function fire() $createCategory = $this->notifynderCategory->add($name, $text); - if (!$createCategory) { + if (! $createCategory) { $this->error('The category has been not created'); + return false; } diff --git a/src/Notifynder/Artisan/CreateGroup.php b/src/Notifynder/Artisan/CreateGroup.php index c7e3ccb..d947478 100755 --- a/src/Notifynder/Artisan/CreateGroup.php +++ b/src/Notifynder/Artisan/CreateGroup.php @@ -48,8 +48,9 @@ public function fire() { $nameGroup = $this->argument('name'); - if (!$this->notifynderGroup->addGroup($nameGroup)) { + if (! $this->notifynderGroup->addGroup($nameGroup)) { $this->error('The name must be a string with dots as namespaces'); + return false; } $this->info("Group {$nameGroup} has Been created"); diff --git a/src/Notifynder/Artisan/DeleteCategory.php b/src/Notifynder/Artisan/DeleteCategory.php index 8c077de..3b512e7 100755 --- a/src/Notifynder/Artisan/DeleteCategory.php +++ b/src/Notifynder/Artisan/DeleteCategory.php @@ -54,8 +54,9 @@ public function fire() $delete = $this->notifynderCategory->deleteByName($indentifier); } - if (!$delete) { + if (! $delete) { $this->error('Category Not found'); + return false; } $this->info('Category has been deleted'); diff --git a/src/Notifynder/Builder/BuilderRules.php b/src/Notifynder/Builder/BuilderRules.php index 20d0baf..ae38e4a 100755 --- a/src/Notifynder/Builder/BuilderRules.php +++ b/src/Notifynder/Builder/BuilderRules.php @@ -47,7 +47,7 @@ protected function isCarbon($value) return true; } - throw new InvalidArgumentException("The value Passed has to be an instance of Carbon\\Carbon"); + throw new InvalidArgumentException('The value Passed has to be an instance of Carbon\\Carbon'); } /** diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index a8631eb..aab9c64 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -181,13 +181,13 @@ public function raw(Closure $closure) */ public function loop($dataToIterate, Closure $builder) { - if (!$this->isIterable($dataToIterate)) { + if (! $this->isIterable($dataToIterate)) { throw new EntityNotIterableException('The data passed must be itarable'); } if (count($dataToIterate) <= 0) { throw new IterableIsEmptyException('The Iterable passed must contain at least one element'); } - + $notifications = []; $newBuilder = new self($this->notifynderCategory); diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 41f35ca..0214f27 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -80,6 +80,7 @@ public function from() if (config('notifynder.polymorphic') == false) { return $this->belongsTo(config('notifynder.model'), 'from_id'); } + return $this->morphTo(); } @@ -94,6 +95,7 @@ public function to() if (config('notifynder.polymorphic') == false) { return $this->belongsTo(config('notifynder.model'), 'to_id'); } + return $this->morphTo(); } @@ -132,6 +134,7 @@ public function scopeWherePolymorphic($query, $toId, $type) if (! $type or config('notifynder.polymorphic') === false) { return $query->where('to_id', $toId); } + return $query->where('to_id', $toId) ->where('to_type', $type); } From 9fe10cf50571a91485b586ed2a792c02a65d8398 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 17:10:36 +0200 Subject: [PATCH 091/210] update readme --- README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aa7bafa..448f4a4 100755 --- a/README.md +++ b/README.md @@ -1,11 +1,20 @@ Notifynder 3.2 - Laravel 5 -========== +========================== + +[![GitHub release](https://img.shields.io/github/release/fenos/Notifynder.svg?style=flat-square)](https://github.com/fenos/Notifynder/releases) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/fenos/Notifynder/master/LICENSE) +[![GitHub issues](https://img.shields.io/github/issues/fenos/Notifynder.svg?style=flat-square)](https://github.com/fenos/Notifynder/issues) +[![Total Downloads](https://poser.pugx.org/fenos/notifynder/downloads.svg?style=flat-square)](https://packagist.org/packages/fenos/notifynder) + +[![Travis branch](https://img.shields.io/travis/fenos/Notifynder/master.svg?style=flat-square)](https://travis-ci.org/fenos/Notifynder/branches) +[![StyleCI](https://styleci.io/repos/18425539/shield)](https://styleci.io/repos/18425539) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fenos/Notifynder/badges/quality-score.png?b=master&style=flat-square)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) +[![Code Climate](https://img.shields.io/codeclimate/github/fenos/Notifynder.svg?style=flat-square)](https://codeclimate.com/github/fenos/Notifynder) +[![Code Climate](https://img.shields.io/codeclimate/issues/github/fenos/Notifynder.svg?style=flat-square)](https://codeclimate.com/github/fenos/Notifynder/issues) + +[![Slack Team](https://img.shields.io/badge/slack-notifynder-orange.svg?style=flat-square)](https://notifynder.slack.com) +[![Slack join](https://img.shields.io/badge/slack-join-green.svg?style=social)](https://notifynder.signup.team) -[![Build Status](https://travis-ci.org/fenos/Notifynder.svg?branch=master)](https://travis-ci.org/fenos/Notifynder) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fenos/Notifynder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) -[![Total Downloads](https://poser.pugx.org/fenos/notifynder/downloads.svg)](https://packagist.org/packages/fenos/notifynder) -[![License](https://poser.pugx.org/fenos/Notifynder/license.png)](https://packagist.org/packages/fenos/Notifynder) -[![Latest Stable Version](https://poser.pugx.org/fenos/notifynder/v/stable.png)](https://packagist.org/packages/fenos/notifynder) Notifynder is designed to manage notifications in a powerful and easy way. With the flexibility that Notifynder offer, It provide a complete API to work with your notifications, @@ -16,8 +25,6 @@ Compatible DBs: **MySql** - **PostgresSql** - **Sqlite** Documentation: **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)** -Community: **[Slack](https://notifynder.slack.com)** | **[Signup](https://notifynder.signup.team)** - - - - ## Installation ## @@ -32,6 +39,10 @@ and run composer update +or run + + composer require fenos/notifynder + ### Step 2 ### @@ -43,7 +54,7 @@ Add the following string to `config/app.php` **Aliases array:** - 'Notifynder'=>Fenos\Notifynder\Facades\Notifynder::class, + 'Notifynder' => Fenos\Notifynder\Facades\Notifynder::class, ### Step 3 ### From 037be814cfb132548c2ade6024731ff62423e8aa Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 17:14:06 +0200 Subject: [PATCH 092/210] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 448f4a4..9007f60 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ Notifynder 3.2 - Laravel 5 [![Travis branch](https://img.shields.io/travis/fenos/Notifynder/master.svg?style=flat-square)](https://travis-ci.org/fenos/Notifynder/branches) [![StyleCI](https://styleci.io/repos/18425539/shield)](https://styleci.io/repos/18425539) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fenos/Notifynder/badges/quality-score.png?b=master&style=flat-square)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) +[![Scrutinizer Build](https://img.shields.io/scrutinizer/build/g/fenos/Notifynder.svg?style=flat-square)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) +[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/fenos/Notifynder.svg?style=flat-square)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) [![Code Climate](https://img.shields.io/codeclimate/github/fenos/Notifynder.svg?style=flat-square)](https://codeclimate.com/github/fenos/Notifynder) [![Code Climate](https://img.shields.io/codeclimate/issues/github/fenos/Notifynder.svg?style=flat-square)](https://codeclimate.com/github/fenos/Notifynder/issues) From 7259633fb036e46b8744034470d7363989f66b43 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 20 May 2016 17:15:32 +0200 Subject: [PATCH 093/210] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9007f60..951335e 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Notifynder 3.2 - Laravel 5 [![GitHub release](https://img.shields.io/github/release/fenos/Notifynder.svg?style=flat-square)](https://github.com/fenos/Notifynder/releases) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/fenos/Notifynder/master/LICENSE) [![GitHub issues](https://img.shields.io/github/issues/fenos/Notifynder.svg?style=flat-square)](https://github.com/fenos/Notifynder/issues) -[![Total Downloads](https://poser.pugx.org/fenos/notifynder/downloads.svg?style=flat-square)](https://packagist.org/packages/fenos/notifynder) +[![Total Downloads](https://img.shields.io/packagist/dt/fenos/notifynder.svg?style=flat-square)](https://packagist.org/packages/fenos/notifynder) [![Travis branch](https://img.shields.io/travis/fenos/Notifynder/master.svg?style=flat-square)](https://travis-ci.org/fenos/Notifynder/branches) [![StyleCI](https://styleci.io/repos/18425539/shield)](https://styleci.io/repos/18425539) From 64dcd273142a076f85ae995abd8c49fa92d64e51 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 30 May 2016 09:42:58 +0200 Subject: [PATCH 094/210] fix issue #139 typo in method name --- src/Notifynder/Notifynder.php | 2 +- src/Notifynder/NotifynderManager.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php index ba85b2f..51d89da 100755 --- a/src/Notifynder/Notifynder.php +++ b/src/Notifynder/Notifynder.php @@ -316,5 +316,5 @@ public function getCategoriesContainer($name); * @param $customSenderName * @return $this */ - public function dipatchWith($customSenderName); + public function dispatchWith($customSenderName); } diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index f131880..cf985cd 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -597,13 +597,23 @@ public function getCategoriesContainer($name) * @param $customSenderName * @return $this */ - public function dipatchWith($customSenderName) + public function dispatchWith($customSenderName) { $this->eventSender = $customSenderName; return $this; } + /** + * @deprecated typo in method name - use dispatchWith() instead + * @param $customSenderName + * @return NotifynderManager + */ + public function dipatchWith($customSenderName) + { + return $this->dispatchWith($customSenderName); + } + /** * Call the custom sender method. * From e373a1e245ead4434885bf582b27d64b7e2bd76c Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 30 May 2016 03:43:16 -0400 Subject: [PATCH 095/210] Applied fixes from StyleCI --- src/Notifynder/NotifynderServiceProvider.php | 3 +-- ...6_06_211555_change_type_to_extra_in_notifications_table.php | 1 - tests/integration/Handler/NotifynderHandlerTest.php | 1 - tests/integration/Notifications/NotificationTest.php | 2 +- tests/integration/Notifications/NotifynderTest.php | 2 -- tests/integration/Senders/SendersTest.php | 3 +-- 6 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 45aec91..c6bc0e5 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -115,7 +115,6 @@ protected function notifications() }); $this->app->singleton('notifynder.notification.repository', function ($app) { - $notificationModel = $app['config']->get('notifynder.notification_model'); $notificationIstance = $app->make($notificationModel); @@ -160,7 +159,7 @@ protected function translator() protected function senders() { $this->app->singleton('notifynder.sender', function ($app) { - return new SenderManager( + return new SenderManager( $app['notifynder.sender.factory'], $app['notifynder.store'], $app[Container::class] diff --git a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php index 850a054..646e638 100755 --- a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php +++ b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php @@ -30,7 +30,6 @@ public function up() public function down() { Schema::table('notifications', function ($table) { - $driver = Config::get('database.driver'); if ($driver === 'mysql' || $driver === 'sqlite') { diff --git a/tests/integration/Handler/NotifynderHandlerTest.php b/tests/integration/Handler/NotifynderHandlerTest.php index cafaf29..8438c07 100755 --- a/tests/integration/Handler/NotifynderHandlerTest.php +++ b/tests/integration/Handler/NotifynderHandlerTest.php @@ -172,7 +172,6 @@ public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynd $users = [1, 2]; return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { - return $builder->category('activation') ->url('hello') ->from(1) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 0549f95..c91575c 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -99,7 +99,7 @@ public function it_will_query_for_notification_by_category_name() $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); $notificationByCategory = $user->getNotifications(false, false, 'desc', function ($query) use ($category) { - $query->byCategory('text'); + $query->byCategory('text'); }); $this->assertCount(10, $notificationByCategory); diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php index 3515181..07c107d 100755 --- a/tests/integration/Notifications/NotifynderTest.php +++ b/tests/integration/Notifications/NotifynderTest.php @@ -124,12 +124,10 @@ public function it_send_multiple_notifications() $allUsers = User::all(); $this->notifynder->loop($allUsers, function ($builder, $user) { - $builder->category('me') ->url('you') ->from(1) ->to($user->id); - })->send(); // should send 10 notifications diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 3a1aac3..6d624ea 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -73,13 +73,12 @@ public function it_send_now_a_mutiple_notification() $sendMultiple = $this->builder->loop($user_ids, function (NotifynderBuilder $builder, $value) use ($category_name) { - return $builder->category($category_name) ->to($value) ->from(2) ->url('www.notifynder.io') ->toArray(); - }); + }); // Send Single $this->senders->sendNow($sendMultiple); From 345718e19cc0c63ecbc383827d4e9801a54fa0e1 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 21:42:43 +0200 Subject: [PATCH 096/210] fix a lot of typo/spelling issues --- src/Notifynder/Artisan/CreateCategory.php | 2 +- src/Notifynder/Artisan/DeleteCategory.php | 14 +++++----- src/Notifynder/Builder/NotifynderBuilder.php | 8 +++--- src/Notifynder/Categories/CategoryManager.php | 2 +- .../Categories/CategoryRepository.php | 8 +++--- src/Notifynder/Contracts/CategoryDB.php | 8 +++--- src/Notifynder/Contracts/NotificationDB.php | 6 ++--- .../Contracts/NotifynderCategory.php | 6 ++--- .../Contracts/NotifynderDispatcher.php | 6 ++--- .../Contracts/NotifynderGroupCategoryDB.php | 1 - .../Contracts/NotifynderTranslator.php | 4 +-- .../Groups/GroupCategoryRepository.php | 14 +++++----- src/Notifynder/Handler/Dispatcher.php | 12 ++++----- src/Notifynder/Handler/NotifynderHandler.php | 4 +-- src/Notifynder/Models/Notification.php | 4 +-- .../Models/NotifynderCollection.php | 2 +- src/Notifynder/Notifable.php | 2 +- .../Notifications/NotificationManager.php | 2 +- .../Notifications/NotificationRepository.php | 8 +++--- src/Notifynder/Notifynder.php | 6 ++--- src/Notifynder/NotifynderManager.php | 8 +++--- src/Notifynder/NotifynderServiceProvider.php | 10 +++---- src/Notifynder/Parsers/NotifynderParser.php | 4 +-- src/Notifynder/Senders/SenderFactory.php | 2 +- src/Notifynder/Senders/SenderManager.php | 10 +++---- .../Translator/TranslatorManager.php | 6 ++--- tests/integration/Senders/SendersTest.php | 27 +++++++++++++++++++ 27 files changed, 106 insertions(+), 80 deletions(-) diff --git a/src/Notifynder/Artisan/CreateCategory.php b/src/Notifynder/Artisan/CreateCategory.php index edb504a..0fad1bb 100755 --- a/src/Notifynder/Artisan/CreateCategory.php +++ b/src/Notifynder/Artisan/CreateCategory.php @@ -23,7 +23,7 @@ class CreateCategory extends Command protected $description = 'Create and store a new notifynder category'; /** - * @var \Fenos\Notifynder\Categories\NotifynderCategory + * @var \\Fenos\Notifynder\Contracts\NotifynderCategory */ private $notifynderCategory; diff --git a/src/Notifynder/Artisan/DeleteCategory.php b/src/Notifynder/Artisan/DeleteCategory.php index 3b512e7..97fd09d 100755 --- a/src/Notifynder/Artisan/DeleteCategory.php +++ b/src/Notifynder/Artisan/DeleteCategory.php @@ -23,7 +23,7 @@ class DeleteCategory extends Command protected $description = 'Delete a notifynder category by ID or Name given'; /** - * @var \Fenos\Notifynder\Categories\NotifynderCategory + * @var \\Fenos\Notifynder\Contracts\NotifynderCategory */ private $notifynderCategory; @@ -46,12 +46,12 @@ public function __construct(NotifynderCategory $notifynderCategory) */ public function fire() { - $indentifier = $this->argument('identifier'); + $identifier = $this->argument('identifier'); - if ($this->isIntegerValue($indentifier)) { - $delete = $this->notifynderCategory->delete($indentifier); + if ($this->isIntegerValue($identifier)) { + $delete = $this->notifynderCategory->delete($identifier); } else { - $delete = $this->notifynderCategory->deleteByName($indentifier); + $delete = $this->notifynderCategory->deleteByName($identifier); } if (! $delete) { @@ -62,9 +62,9 @@ public function fire() $this->info('Category has been deleted'); } - public function isIntegerValue($indentifier) + public function isIntegerValue($identifier) { - return preg_match('/[0-9]/', $indentifier); + return preg_match('/[0-9]/', $identifier); } /** diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php index aab9c64..cf7109a 100755 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ b/src/Notifynder/Builder/NotifynderBuilder.php @@ -19,7 +19,7 @@ * The builder is a main factor of Notifynder, it make sure * that the notification is decorated and validated before * are passed to the Sender Classes. It also helps you to - * create multi notifications with the same simple and easy sintax. + * create multi notifications with the same simple and easy syntax. */ class NotifynderBuilder implements ArrayAccess { @@ -170,7 +170,7 @@ public function raw(Closure $closure) } /** - * Loop the datas for create + * Loop the data for create * multi notifications array. * * @param $dataToIterate @@ -182,7 +182,7 @@ public function raw(Closure $closure) public function loop($dataToIterate, Closure $builder) { if (! $this->isIterable($dataToIterate)) { - throw new EntityNotIterableException('The data passed must be itarable'); + throw new EntityNotIterableException('The data passed must be iterable'); } if (count($dataToIterate) <= 0) { throw new IterableIsEmptyException('The Iterable passed must contain at least one element'); @@ -290,7 +290,7 @@ protected function setEntityAction($from, $property) /** * If the values passed are 2 or more, - * it means that you spefied the entity + * it means that you specified the entity * over then the id. * * @param array $info diff --git a/src/Notifynder/Categories/CategoryManager.php b/src/Notifynder/Categories/CategoryManager.php index 1f78f8e..aca475f 100755 --- a/src/Notifynder/Categories/CategoryManager.php +++ b/src/Notifynder/Categories/CategoryManager.php @@ -9,7 +9,7 @@ /** * Class CategoryManager. * - * The CategoryManager is responsable to deal + * The CategoryManager is responsible to deal * with the notification categories */ class CategoryManager implements NotifynderCategory diff --git a/src/Notifynder/Categories/CategoryRepository.php b/src/Notifynder/Categories/CategoryRepository.php index 84a9aec..d0c5e4f 100755 --- a/src/Notifynder/Categories/CategoryRepository.php +++ b/src/Notifynder/Categories/CategoryRepository.php @@ -9,7 +9,7 @@ /** * Class CategoryRepository. * - * Repository reponsable to approach database + * Repository responsible to approach database * queries of the categories */ class CategoryRepository implements CategoryDB @@ -30,7 +30,7 @@ public function __construct(NotificationCategory $categoryModel) /** * Find By Id. * - * @param $id + * @param $categoryId * @return mixed */ public function find($categoryId) @@ -51,7 +51,7 @@ public function findByName($name) } /** - * Find by names returnig + * Find by names returning * lists of ids. * * @param $name @@ -78,7 +78,7 @@ public function add($name, $text) /** * Delete category by ID. * - * @param $id + * @param $categoryId * @return mixed */ public function delete($categoryId) diff --git a/src/Notifynder/Contracts/CategoryDB.php b/src/Notifynder/Contracts/CategoryDB.php index 5b29863..34d107c 100755 --- a/src/Notifynder/Contracts/CategoryDB.php +++ b/src/Notifynder/Contracts/CategoryDB.php @@ -5,7 +5,7 @@ /** * Class CategoryRepository. * - * Repository reponsable to approach database + * Repository responsible to approach database * queries of the categories */ interface CategoryDB @@ -13,7 +13,7 @@ interface CategoryDB /** * Find By Id. * - * @param $id + * @param $categoryId * @return mixed */ public function find($categoryId); @@ -27,7 +27,7 @@ public function find($categoryId); public function findByName($name); /** - * Find by names returnig + * Find by names returning * lists of ids. * * @param $name @@ -47,7 +47,7 @@ public function add($name, $text); /** * Delete category by ID. * - * @param $id + * @param $categoryId * @return mixed */ public function delete($categoryId); diff --git a/src/Notifynder/Contracts/NotificationDB.php b/src/Notifynder/Contracts/NotificationDB.php index c323539..255fded 100755 --- a/src/Notifynder/Contracts/NotificationDB.php +++ b/src/Notifynder/Contracts/NotificationDB.php @@ -91,7 +91,7 @@ public function deleteByCategory($categoryName, $expired = false); public function deleteLimit($userId, $entity, $number, $order); /** - * Retrive notifications not Read + * Retrieve notifications not Read * You can also limit the number of * Notification if you don't it will get all. * @@ -113,7 +113,7 @@ public function getNotRead( ); /** - * Retrive all notifications, not read + * Retrieve all notifications, not read * in first. * You can also limit the number of * Notifications if you don't, it will get all. @@ -150,7 +150,7 @@ public function countNotRead($toId, $entity, Closure $filterScope = null); * Get last notification of the current * entity. * - * @param $to_id + * @param $toId * @param $entity * @param Closure $filterScope * @return mixed diff --git a/src/Notifynder/Contracts/NotifynderCategory.php b/src/Notifynder/Contracts/NotifynderCategory.php index a69d6f8..d97f719 100755 --- a/src/Notifynder/Contracts/NotifynderCategory.php +++ b/src/Notifynder/Contracts/NotifynderCategory.php @@ -7,7 +7,7 @@ /** * Class CategoryManager. * - * The CategoryManager is responsable to deal + * The CategoryManager is responsible to deal * with the notification categories */ interface NotifynderCategory @@ -34,7 +34,7 @@ public function findByNames(array $name); /** * Find a category by id. * - * @param $id + * @param $categoryId * @throws CategoryNotFoundException * @return mixed */ @@ -52,7 +52,7 @@ public function add($name, $text); /** * Delete category by ID. * - * @param $id + * @param $categoryId * @return mixed */ public function delete($categoryId); diff --git a/src/Notifynder/Contracts/NotifynderDispatcher.php b/src/Notifynder/Contracts/NotifynderDispatcher.php index 4dbb852..e4180e0 100755 --- a/src/Notifynder/Contracts/NotifynderDispatcher.php +++ b/src/Notifynder/Contracts/NotifynderDispatcher.php @@ -11,7 +11,7 @@ interface NotifynderDispatcher { /** * It fire the event associated to the passed key, - * trigging the listener method bound with. + * trigger the listener method bound with. * * @param Notifynder $notifynder * @param string $eventName @@ -22,7 +22,7 @@ interface NotifynderDispatcher public function fire(Notifynder $notifynder, $eventName, $categoryName = null, $values = []); /** - * Deletegate events to categories. + * Delegate events to categories. * * @param Notifynder $notifynder * @param array $data @@ -39,7 +39,7 @@ public function delegate(Notifynder $notifynder, $data, array $events); public function boot(array $listeners); /** - * Tell the disptacher to send + * Tell the dispatcher to send * the notification with a custom * (extended method). * diff --git a/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php b/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php index 0d51cec..9d2d535 100755 --- a/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php +++ b/src/Notifynder/Contracts/NotifynderGroupCategoryDB.php @@ -12,7 +12,6 @@ interface NotifynderGroupCategoryDB * * @param $groupId * @param $categoryId - * @internal param \Fenos\Notifynder\Models\NotificationCategory $category * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static */ public function addCategoryToGroupById($groupId, $categoryId); diff --git a/src/Notifynder/Contracts/NotifynderTranslator.php b/src/Notifynder/Contracts/NotifynderTranslator.php index 256e1d3..78dbe5c 100755 --- a/src/Notifynder/Contracts/NotifynderTranslator.php +++ b/src/Notifynder/Contracts/NotifynderTranslator.php @@ -8,7 +8,7 @@ /** * Class NotifynderTranslator. * - * The Translator is responsable to translate the text + * The Translator is responsible to translate the text * of the notifications with the custom languages that * you define in the configuration file. Translations * are cached in storage/app/notifynder in a json format. @@ -35,7 +35,7 @@ interface NotifynderTranslator public function translate($language, $nameCategory); /** - * Get selected language of tranlsations. + * Get selected language of translations. * * @param $language * @return mixed diff --git a/src/Notifynder/Groups/GroupCategoryRepository.php b/src/Notifynder/Groups/GroupCategoryRepository.php index ff28556..f062d36 100755 --- a/src/Notifynder/Groups/GroupCategoryRepository.php +++ b/src/Notifynder/Groups/GroupCategoryRepository.php @@ -15,7 +15,7 @@ class GroupCategoryRepository implements NotifynderGroupCategoryDB /** * @var NotificationGroup */ - protected $notificationGropup; + protected $notificationGroup; /** * @var NotificationCategory @@ -24,13 +24,13 @@ class GroupCategoryRepository implements NotifynderGroupCategoryDB /** * @param NotifynderCategory $notificationCategory - * @param NotificationGroup $notificationGropup + * @param NotificationGroup $notificationGroup */ public function __construct(NotifynderCategory $notificationCategory, - NotificationGroup $notificationGropup) + NotificationGroup $notificationGroup) { $this->notificationCategory = $notificationCategory; - $this->notificationGropup = $notificationGropup; + $this->notificationGroup = $notificationGroup; } /** @@ -42,7 +42,7 @@ public function __construct(NotifynderCategory $notificationCategory, */ public function addCategoryToGroupById($groupId, $categoryId) { - $group = $this->notificationGropup->find($groupId); + $group = $this->notificationGroup->find($groupId); $group->categories()->attach($categoryId); return $group; @@ -58,7 +58,7 @@ public function addCategoryToGroupById($groupId, $categoryId) */ public function addCategoryToGroupByName($groupName, $categoryName) { - $group = $this->notificationGropup->where('name', $groupName)->first(); + $group = $this->notificationGroup->where('name', $groupName)->first(); $category = $this->notificationCategory->findByName($categoryName); @@ -77,7 +77,7 @@ public function addCategoryToGroupByName($groupName, $categoryName) */ public function addMultipleCategoriesToGroup($groupName, array $names) { - $group = $this->notificationGropup->where('name', $groupName)->first(); + $group = $this->notificationGroup->where('name', $groupName)->first(); $categories = $this->notificationCategory->findByNames($names); diff --git a/src/Notifynder/Handler/Dispatcher.php b/src/Notifynder/Handler/Dispatcher.php index 819abfe..e346206 100755 --- a/src/Notifynder/Handler/Dispatcher.php +++ b/src/Notifynder/Handler/Dispatcher.php @@ -24,7 +24,7 @@ class Dispatcher implements NotifynderDispatcher public static $defaultWildcard = 'Notifynder'; /** - * Sefault sender method. + * Default sender method. * * @var string */ @@ -40,7 +40,7 @@ public function __construct(LaravelDispatcher $event) /** * It fire the event associated to the passed key, - * trigging the listener method bound with. + * trigger the listener method bound with. * * @param Notifynder $notifynder * @param string $eventName @@ -50,7 +50,7 @@ public function __construct(LaravelDispatcher $event) */ public function fire(Notifynder $notifynder, $eventName, $categoryName = null, $values = []) { - // Generete the event from the name given + // Generate the event from the name given $eventName = $this->generateEventName($eventName); // Instantiate the Notifynder event Object that will provide @@ -58,7 +58,7 @@ public function fire(Notifynder $notifynder, $eventName, $categoryName = null, $ // parameter $event = new NotifynderEvent($eventName, $categoryName, $values); - // Fire the event given expecting an array of notifications or falsy + // Fire the event given expecting an array of notifications or false // value to not send the notification $notificationsResult = $this->event->fire($eventName, [$event, $notifynder]); @@ -76,7 +76,7 @@ public function fire(Notifynder $notifynder, $eventName, $categoryName = null, $ } /** - * Deletegate events to categories. + * Delegate events to categories. * * @param Notifynder $notifynder * @param array $data @@ -91,7 +91,7 @@ public function delegate(Notifynder $notifynder, $data, array $events) } /** - * Tell the disptacher to send + * Tell the dispatcher to send * the notification with a custom * (extended method). * diff --git a/src/Notifynder/Handler/NotifynderHandler.php b/src/Notifynder/Handler/NotifynderHandler.php index 75963ea..9d5fa21 100755 --- a/src/Notifynder/Handler/NotifynderHandler.php +++ b/src/Notifynder/Handler/NotifynderHandler.php @@ -74,7 +74,7 @@ protected function listenerIsRegistered($eventName) */ protected function getEventName($event) { - // Remove the Notiynder namespaces for + // Remove the Notifynder namespaces for // the find the method $event = str_replace(Dispatcher::$defaultWildcard.'.', '', $event); @@ -82,7 +82,7 @@ protected function getEventName($event) ? explode('@', $event) : explode('.', $event); - // Check if the name has been splited in 2 + // Check if the name has been splitted in 2 if (count($eventNameSpace) > 1) { array_shift($eventNameSpace); } diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 04c2bb0..53e17ef 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -75,7 +75,7 @@ public function body() public function from() { // check if on the configurations file there is the option - // polymorphic setted to true, if so Notifynder will work + // polymorphic set to true, if so Notifynder will work // polymorphic. if (config('notifynder.polymorphic') == false) { return $this->belongsTo(config('notifynder.model'), 'from_id'); @@ -90,7 +90,7 @@ public function from() public function to() { // check if on the configurations file there is the option - // polymorphic setted to true, if so Notifynder will work + // polymorphic set to true, if so Notifynder will work // polymorphic. if (config('notifynder.polymorphic') == false) { return $this->belongsTo(config('notifynder.model'), 'to_id'); diff --git a/src/Notifynder/Models/NotifynderCollection.php b/src/Notifynder/Models/NotifynderCollection.php index 11563c1..c972335 100755 --- a/src/Notifynder/Models/NotifynderCollection.php +++ b/src/Notifynder/Models/NotifynderCollection.php @@ -44,7 +44,7 @@ public function translator() */ public function translate($language) { - // Loop throught the notifications + // Loop through the notifications foreach ($this->items as $key => $item) { try { $translation = $this->translator() diff --git a/src/Notifynder/Notifable.php b/src/Notifynder/Notifable.php index 334bc3b..7ae4dd1 100755 --- a/src/Notifynder/Notifable.php +++ b/src/Notifynder/Notifable.php @@ -21,7 +21,7 @@ trait Notifable public function notifications() { // check if on the configurations file there is the option - // polymorphic setted to true, if so Notifynder will work + // polymorphic set to true, if so Notifynder will work // polymorphic. if (config('notifynder.polymorphic') == false) { return $this->morphMany(config('notifynder.notification_model'), 'to'); diff --git a/src/Notifynder/Notifications/NotificationManager.php b/src/Notifynder/Notifications/NotificationManager.php index 96f5af6..44a9f87 100755 --- a/src/Notifynder/Notifications/NotificationManager.php +++ b/src/Notifynder/Notifications/NotificationManager.php @@ -12,7 +12,7 @@ /** * Class NotifynderNotification. * - * The notification manager is responsable to manage the CRUD operations + * The notification manager is responsible to manage the CRUD operations * of the notifications. */ class NotificationManager implements NotifynderNotification diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index 88299f8..fea067b 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -142,7 +142,7 @@ public function delete($notificationId) * Delete All notifications about the * current user. * - * @param $to_id int + * @param $toId int * @param $entity * @return bool */ @@ -210,7 +210,7 @@ public function deleteLimit($userId, $entity, $number, $order) } /** - * Retrive notifications not Read + * Retrieve notifications not Read * You can also limit the number of * Notification if you don't it will get all. * @@ -250,7 +250,7 @@ public function getNotRead( } /** - * Retrive all notifications, not read + * Retrieve all notifications, not read * in first. * You can also limit the number of * Notifications if you don't, it will get all. @@ -333,7 +333,7 @@ public function getLastNotification($toId, $entity, Closure $filterScope = null) * entity of a specific category. * * @param $category - * @param $to_id + * @param $toId * @param $entity * @param Closure $filterScope * @return mixed diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php index ba85b2f..6d83630 100755 --- a/src/Notifynder/Notifynder.php +++ b/src/Notifynder/Notifynder.php @@ -9,7 +9,7 @@ * Class Notifynder. * * Notifynder is a Facade Class that has - * all the methods necesessary to use the library. + * all the methods necessary to use the library. * * Notifynder allow you to have a flexible notification * management. It will provide you a nice and easy API @@ -28,7 +28,7 @@ public function category($name); /** * Define an entity when Notifynder is - * used Polymorpically. + * used Polymorphically. * * @param $name * @return $this @@ -134,7 +134,7 @@ public function delete($notificationId); /** * Delete number of notifications - * secified of the given entity. + * specified of the given entity. * * @param $toId * @param $number diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index f131880..017c355 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -16,7 +16,7 @@ * Class Notifynder. * * Notifynder is a Facade Class that has - * all the methods necesessary to use the library. + * all the methods necessary to use the library. * * Notifynder allow you to have a flexible notification * management. It will provide you a nice and easy API @@ -139,7 +139,7 @@ public function category($name) /** * Define an entity when Notifynder is - * used Polymorpically. + * used Polymorphically. * * @param $name * @return $this @@ -167,7 +167,7 @@ public function addCategory($name, $text) * Update a category. * * @param array $updates - * @param $id + * @param $categoryId * @return mixed */ public function updateCategory(array $updates, $categoryId) @@ -317,7 +317,7 @@ public function delete($notificationId) /** * Delete number of notifications - * secified of the given entity. + * specified of the given entity. * * @param $toId * @param $number diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 45aec91..15e248b 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -96,7 +96,7 @@ protected function categories() ); }); - $this->app->singleton('notifynder.category.repository', function ($app) { + $this->app->singleton('notifynder.category.repository', function () { return new CategoryRepository( new NotificationCategory() ); @@ -117,10 +117,10 @@ protected function notifications() $this->app->singleton('notifynder.notification.repository', function ($app) { $notificationModel = $app['config']->get('notifynder.notification_model'); - $notificationIstance = $app->make($notificationModel); + $notificationInstance = $app->make($notificationModel); return new NotificationRepository( - $notificationIstance, + $notificationInstance, $app['db'] ); }); @@ -199,7 +199,7 @@ protected function groups() ); }); - $this->app->singleton('notifynder.group.repository', function ($app) { + $this->app->singleton('notifynder.group.repository', function () { return new GroupRepository( new NotificationGroup() ); @@ -267,7 +267,7 @@ protected function config() $this->mergeConfigFrom(__DIR__.'/../config/notifynder.php', 'notifynder'); // Set use strict_extra config option, - // you can toggle it in the configuraiton file + // you can toggle it in the configuration file $strictParam = $this->app['config']->get('notifynder.strict_extra', false); NotifynderParser::setStrictExtra($strictParam); } diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php index 013adfc..5b0aa7e 100755 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ b/src/Notifynder/Parsers/NotifynderParser.php @@ -11,7 +11,7 @@ class NotifynderParser { /** - * Regex to get values between curly brachet {$value}. + * Regex to get values between curly bracket {$value}. */ const RULE = '/\{(.+?)(?:\{(.+)\})?\}/'; @@ -85,7 +85,7 @@ protected function getValues($body) } /** - * Trying to transform extra in from few datatypes + * Trying to transform extra in from few data types * to array type. * * @param $extra diff --git a/src/Notifynder/Senders/SenderFactory.php b/src/Notifynder/Senders/SenderFactory.php index 9518888..5a795cc 100755 --- a/src/Notifynder/Senders/SenderFactory.php +++ b/src/Notifynder/Senders/SenderFactory.php @@ -51,7 +51,7 @@ public function getSender($infoNotifications, $category = null) $infoNotifications = $infoNotifications->toArray(); } - // if the array is multidimesional + // if the array is multidimensional // it means that we want to send // multiple notifications if ($this->isMultiArray($infoNotifications)) { diff --git a/src/Notifynder/Senders/SenderManager.php b/src/Notifynder/Senders/SenderManager.php index 5dfe131..d525a4b 100755 --- a/src/Notifynder/Senders/SenderManager.php +++ b/src/Notifynder/Senders/SenderManager.php @@ -152,7 +152,7 @@ public function customSender($customMethod, $notification) // with the if ($extendedSender instanceof Closure) { - // I invoke the closue expecting an Instance of a custorm + // I invoke the closure expecting an Instance of a custom // Sender $invoker = call_user_func_array($extendedSender, [$notification, $this->container]); @@ -162,15 +162,15 @@ public function customSender($customMethod, $notification) return $invoker->send($this); } - // If the dev is attemping to create a custom + // If the dev is attempting to create a custom // way of storing notifications then - // i'll pass the storenotification contract + // i'll pass the store notification contract if ($invoker instanceof DefaultSender) { return $invoker->send($this->storeNotification); } } - $error = 'The extention must be an instance of Closure'; + $error = 'The extension must be an instance of Closure'; throw new LogicException($error); } @@ -180,7 +180,7 @@ public function customSender($customMethod, $notification) /** * When calling a not existing method - * try to resolve with an exteded. + * try to resolve with an extended. * * @param $name * @param $arguments diff --git a/src/Notifynder/Translator/TranslatorManager.php b/src/Notifynder/Translator/TranslatorManager.php index 71b255b..df5a04a 100755 --- a/src/Notifynder/Translator/TranslatorManager.php +++ b/src/Notifynder/Translator/TranslatorManager.php @@ -10,7 +10,7 @@ /** * Class NotifynderTranslator. * - * The Translator is responsable to translate the text + * The Translator is responsible to translate the text * of the notifications with the custom languages that * you'll define in the configuration file. Translations * are cached in storage/app/notifynder in a json format. @@ -67,7 +67,7 @@ public function translate($language, $nameCategory) } /** - * Get selected language of tranlsations. + * Get selected language of translations. * * @param $language * @return mixed @@ -127,7 +127,7 @@ protected function cacheFromConfig() // I put the edited content in the cached file $this->compiler->cacheFile($fileTranslation); - // return the traslations + // return the translations return $fileTranslation; } } diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 3a1aac3..9fd5496 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -130,4 +130,31 @@ public function it_send_with_an_custom_sender() $this->assertCount(1, Notification::all()); } + + /** @test */ + public function it_send_multiple_with_an_custom_sender() + { + $this->senders->extend('sendCustom', function ($notification, $app) { + dd($notification); + }); + + $category_name = 'my.category'; + $this->createCategory(['name' => $category_name]); + + $multipleNotifications = []; + $multipleNotifications[] = $this->builder->category($category_name) + ->to(1) + ->from(2) + ->url('www.notifynder.io') + ->toArray(); + $multipleNotifications[] = $this->builder->category($category_name) + ->to(2) + ->from(1) + ->url('notifynder.com') + ->toArray(); + + $this->senders->sendCustom($multipleNotifications); + + $this->assertCount(1, Notification::all()); + } } From abf217d23e5a4c019b239f088c797ab1f116f7e8 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 15:42:54 -0400 Subject: [PATCH 097/210] Applied fixes from StyleCI --- src/Notifynder/NotifynderServiceProvider.php | 3 +-- ...6_06_211555_change_type_to_extra_in_notifications_table.php | 1 - tests/integration/Handler/NotifynderHandlerTest.php | 1 - tests/integration/Notifications/NotificationTest.php | 2 +- tests/integration/Notifications/NotifynderTest.php | 2 -- tests/integration/Senders/SendersTest.php | 3 +-- 6 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 15e248b..8167cc5 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -115,7 +115,6 @@ protected function notifications() }); $this->app->singleton('notifynder.notification.repository', function ($app) { - $notificationModel = $app['config']->get('notifynder.notification_model'); $notificationInstance = $app->make($notificationModel); @@ -160,7 +159,7 @@ protected function translator() protected function senders() { $this->app->singleton('notifynder.sender', function ($app) { - return new SenderManager( + return new SenderManager( $app['notifynder.sender.factory'], $app['notifynder.store'], $app[Container::class] diff --git a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php index 850a054..646e638 100755 --- a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php +++ b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php @@ -30,7 +30,6 @@ public function up() public function down() { Schema::table('notifications', function ($table) { - $driver = Config::get('database.driver'); if ($driver === 'mysql' || $driver === 'sqlite') { diff --git a/tests/integration/Handler/NotifynderHandlerTest.php b/tests/integration/Handler/NotifynderHandlerTest.php index cafaf29..8438c07 100755 --- a/tests/integration/Handler/NotifynderHandlerTest.php +++ b/tests/integration/Handler/NotifynderHandlerTest.php @@ -172,7 +172,6 @@ public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynd $users = [1, 2]; return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { - return $builder->category('activation') ->url('hello') ->from(1) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 0549f95..c91575c 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -99,7 +99,7 @@ public function it_will_query_for_notification_by_category_name() $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); $notificationByCategory = $user->getNotifications(false, false, 'desc', function ($query) use ($category) { - $query->byCategory('text'); + $query->byCategory('text'); }); $this->assertCount(10, $notificationByCategory); diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php index 3515181..07c107d 100755 --- a/tests/integration/Notifications/NotifynderTest.php +++ b/tests/integration/Notifications/NotifynderTest.php @@ -124,12 +124,10 @@ public function it_send_multiple_notifications() $allUsers = User::all(); $this->notifynder->loop($allUsers, function ($builder, $user) { - $builder->category('me') ->url('you') ->from(1) ->to($user->id); - })->send(); // should send 10 notifications diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 9fd5496..254e3a1 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -73,13 +73,12 @@ public function it_send_now_a_mutiple_notification() $sendMultiple = $this->builder->loop($user_ids, function (NotifynderBuilder $builder, $value) use ($category_name) { - return $builder->category($category_name) ->to($value) ->from(2) ->url('www.notifynder.io') ->toArray(); - }); + }); // Send Single $this->senders->sendNow($sendMultiple); From 15d88fe083a5cfc34d41bda291397061aa0544e8 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 21:44:51 +0200 Subject: [PATCH 098/210] remove the old method - breaking change but related to PR #147 we clean the whole project --- src/Notifynder/NotifynderManager.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php index cf985cd..fd38710 100755 --- a/src/Notifynder/NotifynderManager.php +++ b/src/Notifynder/NotifynderManager.php @@ -604,16 +604,6 @@ public function dispatchWith($customSenderName) return $this; } - /** - * @deprecated typo in method name - use dispatchWith() instead - * @param $customSenderName - * @return NotifynderManager - */ - public function dipatchWith($customSenderName) - { - return $this->dispatchWith($customSenderName); - } - /** * Call the custom sender method. * From 0d971b444e3b1abc0d25f3b34213278f0a7d9b71 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 22:02:44 +0200 Subject: [PATCH 099/210] remove unwanted unit test --- tests/integration/Senders/SendersTest.php | 27 ----------------------- 1 file changed, 27 deletions(-) diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 9fd5496..3a1aac3 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -130,31 +130,4 @@ public function it_send_with_an_custom_sender() $this->assertCount(1, Notification::all()); } - - /** @test */ - public function it_send_multiple_with_an_custom_sender() - { - $this->senders->extend('sendCustom', function ($notification, $app) { - dd($notification); - }); - - $category_name = 'my.category'; - $this->createCategory(['name' => $category_name]); - - $multipleNotifications = []; - $multipleNotifications[] = $this->builder->category($category_name) - ->to(1) - ->from(2) - ->url('www.notifynder.io') - ->toArray(); - $multipleNotifications[] = $this->builder->category($category_name) - ->to(2) - ->from(1) - ->url('notifynder.com') - ->toArray(); - - $this->senders->sendCustom($multipleNotifications); - - $this->assertCount(1, Notification::all()); - } } From bd5e3d9493c0f4a63a10db0e639efbc4e086fa0f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 22:04:08 +0200 Subject: [PATCH 100/210] add unittest for custom sender with multiple notifications --- tests/integration/Senders/SendersTest.php | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 3a1aac3..472a8f0 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -130,4 +130,31 @@ public function it_send_with_an_custom_sender() $this->assertCount(1, Notification::all()); } + + /** @test */ + public function it_send_multiple_with_an_custom_sender() + { + $this->senders->extend('sendCustom', function ($notification, $app) { + return new CustomDefaultSender($notification, $app->make('notifynder')); + }); + + $category_name = 'my.category'; + $this->createCategory(['name' => $category_name]); + + $multipleNotifications = []; + $multipleNotifications[] = $this->builder->category($category_name) + ->to(1) + ->from(2) + ->url('www.notifynder.io') + ->toArray(); + $multipleNotifications[] = $this->builder->category($category_name) + ->to(2) + ->from(1) + ->url('notifynder.com') + ->toArray(); + + $this->senders->sendCustom($multipleNotifications); + + $this->assertCount(2, Notification::all()); + } } From 2b217db824c9010c0b623f5c00a5b516c59c23a4 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 16:04:17 -0400 Subject: [PATCH 101/210] Applied fixes from StyleCI --- src/Notifynder/NotifynderServiceProvider.php | 3 +-- ...6_06_211555_change_type_to_extra_in_notifications_table.php | 1 - tests/integration/Handler/NotifynderHandlerTest.php | 1 - tests/integration/Notifications/NotificationTest.php | 2 +- tests/integration/Notifications/NotifynderTest.php | 2 -- tests/integration/Senders/SendersTest.php | 3 +-- 6 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 45aec91..c6bc0e5 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -115,7 +115,6 @@ protected function notifications() }); $this->app->singleton('notifynder.notification.repository', function ($app) { - $notificationModel = $app['config']->get('notifynder.notification_model'); $notificationIstance = $app->make($notificationModel); @@ -160,7 +159,7 @@ protected function translator() protected function senders() { $this->app->singleton('notifynder.sender', function ($app) { - return new SenderManager( + return new SenderManager( $app['notifynder.sender.factory'], $app['notifynder.store'], $app[Container::class] diff --git a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php index 850a054..646e638 100755 --- a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php +++ b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php @@ -30,7 +30,6 @@ public function up() public function down() { Schema::table('notifications', function ($table) { - $driver = Config::get('database.driver'); if ($driver === 'mysql' || $driver === 'sqlite') { diff --git a/tests/integration/Handler/NotifynderHandlerTest.php b/tests/integration/Handler/NotifynderHandlerTest.php index cafaf29..8438c07 100755 --- a/tests/integration/Handler/NotifynderHandlerTest.php +++ b/tests/integration/Handler/NotifynderHandlerTest.php @@ -172,7 +172,6 @@ public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynd $users = [1, 2]; return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { - return $builder->category('activation') ->url('hello') ->from(1) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 0549f95..c91575c 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -99,7 +99,7 @@ public function it_will_query_for_notification_by_category_name() $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); $notificationByCategory = $user->getNotifications(false, false, 'desc', function ($query) use ($category) { - $query->byCategory('text'); + $query->byCategory('text'); }); $this->assertCount(10, $notificationByCategory); diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php index 3515181..07c107d 100755 --- a/tests/integration/Notifications/NotifynderTest.php +++ b/tests/integration/Notifications/NotifynderTest.php @@ -124,12 +124,10 @@ public function it_send_multiple_notifications() $allUsers = User::all(); $this->notifynder->loop($allUsers, function ($builder, $user) { - $builder->category('me') ->url('you') ->from(1) ->to($user->id); - })->send(); // should send 10 notifications diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 472a8f0..808e359 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -73,13 +73,12 @@ public function it_send_now_a_mutiple_notification() $sendMultiple = $this->builder->loop($user_ids, function (NotifynderBuilder $builder, $value) use ($category_name) { - return $builder->category($category_name) ->to($value) ->from(2) ->url('www.notifynder.io') ->toArray(); - }); + }); // Send Single $this->senders->sendNow($sendMultiple); From ae9e0aeae6a581e6f0d6d2219c6678926f56146b Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 22:10:59 +0200 Subject: [PATCH 102/210] Issue #145 - unique the `text` & `notify_body` attributes --- src/Notifynder/Models/Notification.php | 12 +++++++++++- src/Notifynder/Models/NotifynderCollection.php | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 04c2bb0..0d62565 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -142,7 +142,7 @@ public function scopeWherePolymorphic($query, $toId, $type) /** * Get parsed body attributes. * - * @return mixed + * @return string */ public function getNotifyBodyAttribute() { @@ -151,6 +151,16 @@ public function getNotifyBodyAttribute() return $notifynderParse->parse($this); } + /** + * Get parsed body attributes. + * + * @return string + */ + public function getTextAttribute() + { + return $this->notify_body; + } + /** * @param $value * @return \Fenos\Notifynder\Notifications\ExtraParams diff --git a/src/Notifynder/Models/NotifynderCollection.php b/src/Notifynder/Models/NotifynderCollection.php index 11563c1..7b2ad88 100755 --- a/src/Notifynder/Models/NotifynderCollection.php +++ b/src/Notifynder/Models/NotifynderCollection.php @@ -71,7 +71,8 @@ public function parse() $parser = new NotifynderParser(); foreach ($this->items as $key => $item) { - $this->items[$key]['text'] = $parser->parse($item); + $this->items[$key]['notify_body'] = $parser->parse($item); + $this->items[$key]['text'] = $this->items[$key]['notify_body']; } return $this; From 8c071156a74791c3deca7172dcb6e9ca6db93184 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 3 Jun 2016 16:11:13 -0400 Subject: [PATCH 103/210] Applied fixes from StyleCI --- src/Notifynder/NotifynderServiceProvider.php | 3 +-- ...6_06_211555_change_type_to_extra_in_notifications_table.php | 1 - tests/integration/Handler/NotifynderHandlerTest.php | 1 - tests/integration/Notifications/NotificationTest.php | 2 +- tests/integration/Notifications/NotifynderTest.php | 2 -- tests/integration/Senders/SendersTest.php | 3 +-- 6 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 45aec91..c6bc0e5 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -115,7 +115,6 @@ protected function notifications() }); $this->app->singleton('notifynder.notification.repository', function ($app) { - $notificationModel = $app['config']->get('notifynder.notification_model'); $notificationIstance = $app->make($notificationModel); @@ -160,7 +159,7 @@ protected function translator() protected function senders() { $this->app->singleton('notifynder.sender', function ($app) { - return new SenderManager( + return new SenderManager( $app['notifynder.sender.factory'], $app['notifynder.store'], $app[Container::class] diff --git a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php index 850a054..646e638 100755 --- a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php +++ b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php @@ -30,7 +30,6 @@ public function up() public function down() { Schema::table('notifications', function ($table) { - $driver = Config::get('database.driver'); if ($driver === 'mysql' || $driver === 'sqlite') { diff --git a/tests/integration/Handler/NotifynderHandlerTest.php b/tests/integration/Handler/NotifynderHandlerTest.php index cafaf29..8438c07 100755 --- a/tests/integration/Handler/NotifynderHandlerTest.php +++ b/tests/integration/Handler/NotifynderHandlerTest.php @@ -172,7 +172,6 @@ public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynd $users = [1, 2]; return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { - return $builder->category('activation') ->url('hello') ->from(1) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 0549f95..c91575c 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -99,7 +99,7 @@ public function it_will_query_for_notification_by_category_name() $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); $notificationByCategory = $user->getNotifications(false, false, 'desc', function ($query) use ($category) { - $query->byCategory('text'); + $query->byCategory('text'); }); $this->assertCount(10, $notificationByCategory); diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php index 3515181..07c107d 100755 --- a/tests/integration/Notifications/NotifynderTest.php +++ b/tests/integration/Notifications/NotifynderTest.php @@ -124,12 +124,10 @@ public function it_send_multiple_notifications() $allUsers = User::all(); $this->notifynder->loop($allUsers, function ($builder, $user) { - $builder->category('me') ->url('you') ->from(1) ->to($user->id); - })->send(); // should send 10 notifications diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 3a1aac3..6d624ea 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -73,13 +73,12 @@ public function it_send_now_a_mutiple_notification() $sendMultiple = $this->builder->loop($user_ids, function (NotifynderBuilder $builder, $value) use ($category_name) { - return $builder->category($category_name) ->to($value) ->from(2) ->url('www.notifynder.io') ->toArray(); - }); + }); // Send Single $this->senders->sendNow($sendMultiple); From 9bd57502277cf35bfa95f49a4ac7a844a08ae569 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 8 Jun 2016 16:22:23 +0200 Subject: [PATCH 104/210] Issue #103: make stack_id null to add methods on the model hasStack() & getStack() --- src/Notifynder/Models/Notification.php | 36 ++++++++++++++++++ .../Notifications/NotificationRepository.php | 37 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index fba636e..86c9ac5 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -5,6 +5,7 @@ use Fenos\Notifynder\Notifications\ExtraParams; use Fenos\Notifynder\Parsers\NotifynderParser; use Illuminate\Contracts\Container\Container; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Carbon\Carbon; use Illuminate\Support\Arr; @@ -215,4 +216,39 @@ protected function mergeFillable() return $fillables; } + + /** + * Filter Scope by stack. + * + * @param $query + * @param $stackId + * @return mixed + */ + public function scopeByStack($query, $stackId) + { + return $query->where('stack_id', $stackId); + } + + /** + * Check if this notification is part of a stack. + * + * @return bool + */ + public function hasStack() + { + return !is_null($this->stack_id); + } + + /** + * Get the full stack of notifications if this has one. + * + * @return null|Collection + */ + public function getStack() + { + if($this->hasStack()) { + return static::byStack($this->stack_id)->get(); + } + return null; + } } diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php index 344cdf3..6a57415 100755 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ b/src/Notifynder/Notifications/NotificationRepository.php @@ -376,4 +376,41 @@ protected function applyFilter(Closure $filterScope = null, $query) return $query; } + + /** + * Retrive all notifications, in a stack. + * You can also limit the number of + * Notifications if you don't, it will get all. + * + * @param $stackId + * @param null $limit + * @param int|null $paginate + * @param string $orderDate + * @param Closure $filterScope + * @return mixed + */ + public function getStack( + $stackId, + $limit = null, + $paginate = null, + $orderDate = 'desc', + Closure $filterScope = null + ) { + $query = $this->notification->with('body', 'from', 'to') + ->byStack($stackId) + ->orderBy('read', 'ASC') + ->orderBy('created_at', $orderDate); + + if ($limit && ! $paginate) { + $query->limit($limit); + } + + $query = $this->applyFilter($filterScope, $query); + + if (is_int(intval($paginate)) && $paginate) { + return $query->paginate($limit); + } + + return $query->get(); + } } From f5f39a74ebebb2ef7a7826ef7e7a63309385e4c7 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 8 Jun 2016 10:22:33 -0400 Subject: [PATCH 105/210] Applied fixes from StyleCI --- src/Notifynder/Models/Notification.php | 5 ++--- src/Notifynder/NotifynderServiceProvider.php | 3 +-- ...06_211555_change_type_to_extra_in_notifications_table.php | 1 - tests/integration/Handler/NotifynderHandlerTest.php | 1 - tests/integration/Notifications/NotificationTest.php | 2 +- tests/integration/Notifications/NotifynderTest.php | 2 -- tests/integration/Senders/SendersTest.php | 3 +-- 7 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 86c9ac5..65377eb 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -236,7 +236,7 @@ public function scopeByStack($query, $stackId) */ public function hasStack() { - return !is_null($this->stack_id); + return ! is_null($this->stack_id); } /** @@ -246,9 +246,8 @@ public function hasStack() */ public function getStack() { - if($this->hasStack()) { + if ($this->hasStack()) { return static::byStack($this->stack_id)->get(); } - return null; } } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index a638d0a..5f35e72 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -115,7 +115,6 @@ protected function notifications() }); $this->app->singleton('notifynder.notification.repository', function ($app) { - $notificationModel = $app['config']->get('notifynder.notification_model'); $notificationIstance = $app->make($notificationModel); @@ -160,7 +159,7 @@ protected function translator() protected function senders() { $this->app->singleton('notifynder.sender', function ($app) { - return new SenderManager( + return new SenderManager( $app['notifynder.sender.factory'], $app['notifynder.store'], $app[Container::class] diff --git a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php index 850a054..646e638 100755 --- a/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php +++ b/src/migrations/2015_06_06_211555_change_type_to_extra_in_notifications_table.php @@ -30,7 +30,6 @@ public function up() public function down() { Schema::table('notifications', function ($table) { - $driver = Config::get('database.driver'); if ($driver === 'mysql' || $driver === 'sqlite') { diff --git a/tests/integration/Handler/NotifynderHandlerTest.php b/tests/integration/Handler/NotifynderHandlerTest.php index cafaf29..8438c07 100755 --- a/tests/integration/Handler/NotifynderHandlerTest.php +++ b/tests/integration/Handler/NotifynderHandlerTest.php @@ -172,7 +172,6 @@ public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynd $users = [1, 2]; return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { - return $builder->category('activation') ->url('hello') ->from(1) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 825f79a..52a3678 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -99,7 +99,7 @@ public function it_will_query_for_notification_by_category_name() $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); $notificationByCategory = $user->getNotifications(false, false, 'desc', function ($query) use ($category) { - $query->byCategory('text'); + $query->byCategory('text'); }); $this->assertCount(10, $notificationByCategory); diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php index 3515181..07c107d 100755 --- a/tests/integration/Notifications/NotifynderTest.php +++ b/tests/integration/Notifications/NotifynderTest.php @@ -124,12 +124,10 @@ public function it_send_multiple_notifications() $allUsers = User::all(); $this->notifynder->loop($allUsers, function ($builder, $user) { - $builder->category('me') ->url('you') ->from(1) ->to($user->id); - })->send(); // should send 10 notifications diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php index 4ac0617..5862b5c 100755 --- a/tests/integration/Senders/SendersTest.php +++ b/tests/integration/Senders/SendersTest.php @@ -81,13 +81,12 @@ public function it_send_now_a_mutiple_notification() $sendMultiple = $this->builder->loop($user_ids, function (NotifynderBuilder $builder, $value) use ($category_name) { - return $builder->category($category_name) ->to($value) ->from(2) ->url('www.notifynder.io') ->toArray(); - }); + }); // Send Single $this->senders->sendNow($sendMultiple); From 755f0c69e838bd2ef805e483bf30f8e4d0007eb1 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 8 Jun 2016 17:33:12 +0200 Subject: [PATCH 106/210] add unittest for scope --- .../Notifications/NotificationTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 52a3678..8cd91d2 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -193,4 +193,21 @@ public function it_retrieve_notifications_toarray() $this->assertInternalType('array', $notifications[0]['extra']); $this->assertEquals('Amazing', $notifications[0]['extra']['look']); } + + /** @test */ + public function it_retrieve_notifications_by_stack_id() + { + $text = 'stack body text'; + $category = $this->createCategory(['text' => $text]); + + $this->createMultipleNotifications(['category_id' => $category->id]); + + $notifications = \Fenos\Notifynder\Models\Notification::byStack(1)->get(); + + foreach($notifications as $notification) { + $this->assertEquals($text, $notification->text); + $this->assertEquals(1, $notification->stack_id); + $this->assertTrue($notification->hasStack()); + } + } } From bfa587c02e68344ab4108cc73a9b080c5dd1d1a6 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 8 Jun 2016 11:33:21 -0400 Subject: [PATCH 107/210] Applied fixes from StyleCI --- tests/integration/Notifications/NotificationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php index 8cd91d2..7e80427 100755 --- a/tests/integration/Notifications/NotificationTest.php +++ b/tests/integration/Notifications/NotificationTest.php @@ -204,7 +204,7 @@ public function it_retrieve_notifications_by_stack_id() $notifications = \Fenos\Notifynder\Models\Notification::byStack(1)->get(); - foreach($notifications as $notification) { + foreach ($notifications as $notification) { $this->assertEquals($text, $notification->text); $this->assertEquals(1, $notification->stack_id); $this->assertTrue($notification->hasStack()); From 5bb0218ff292886171a699a4a21c0f8d71582f05 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 17 Jun 2016 16:19:56 +0200 Subject: [PATCH 108/210] clean repo to absolute basics --- .travis.yml => .old.travis.yml | 0 composer.json | 5 +- spec/.gitkeep | 0 .../Builder/NotifynderBuilderSpec.php | 197 ------ .../Categories/CategoryManagerSpec.php | 80 --- .../Notifynder/Groups/GroupManagerSpec.php | 123 ---- .../Notifynder/Handler/DispatcherSpec.php | 60 -- .../Notifications/NotificationManagerSpec.php | 220 ------ .../Parsers/NotifynderParserSpec.php | 126 ---- .../Notifynder/Senders/SendMultipleSpec.php | 32 - spec/Fenos/Notifynder/Senders/SendOneSpec.php | 45 -- .../Notifynder/Senders/SenderFactorySpec.php | 56 -- .../Notifynder/Senders/SenderManagerSpec.php | 114 --- .../Translator/TranslatorManagerSpec.php | 128 ---- src/Notifynder/Artisan/CreateCategory.php | 76 -- src/Notifynder/Artisan/CreateGroup.php | 70 -- src/Notifynder/Artisan/DeleteCategory.php | 81 --- .../Artisan/PushCategoryToGroup.php | 116 ---- src/Notifynder/Builder/BuilderRules.php | 159 ----- src/Notifynder/Builder/NotifynderBuilder.php | 383 ---------- src/Notifynder/Categories/CategoryManager.php | 133 ---- .../Categories/CategoryRepository.php | 114 --- src/Notifynder/Collections/Config.php | 70 ++ src/Notifynder/Contracts/CategoryDB.php | 71 -- src/Notifynder/Contracts/ConfigContract.php | 24 + src/Notifynder/Contracts/DefaultSender.php | 21 - src/Notifynder/Contracts/NotificationDB.php | 171 ----- src/Notifynder/Contracts/NotifyListener.php | 20 - .../Contracts/NotifynderCategory.php | 76 -- .../Contracts/NotifynderContract.php | 72 ++ .../Contracts/NotifynderDispatcher.php | 59 -- src/Notifynder/Contracts/NotifynderGroup.php | 67 -- .../Contracts/NotifynderGroupCategoryDB.php | 38 - .../Contracts/NotifynderGroupDB.php | 41 -- .../Contracts/NotifynderNotification.php | 170 ----- src/Notifynder/Contracts/NotifynderSender.php | 78 --- .../Contracts/NotifynderTranslator.php | 52 -- src/Notifynder/Contracts/Sender.php | 17 - .../Contracts/StoreNotification.php | 28 - .../Exceptions/CategoryNotFoundException.php | 12 - .../Exceptions/EntityNotIterableException.php | 12 - .../EntityNotSpecifiedException.php | 12 - .../Exceptions/ExtraParamsException.php | 9 - .../Exceptions/IterableIsEmptyException.php | 12 - .../NotificationBuilderException.php | 12 - .../NotificationLanguageNotFoundException.php | 12 - .../NotificationNotFoundException.php | 12 - ...tificationTranslationNotFoundException.php | 12 - .../NotifynderGroupNotFoundException.php | 12 - src/Notifynder/Facades/Notifynder.php | 18 - .../Groups/GroupCategoryRepository.php | 90 --- src/Notifynder/Groups/GroupManager.php | 147 ---- src/Notifynder/Groups/GroupRepository.php | 70 -- src/Notifynder/Handler/Dispatcher.php | 149 ---- src/Notifynder/Handler/NotifynderEvent.php | 85 --- src/Notifynder/Handler/NotifynderHandler.php | 121 ---- src/Notifynder/Helpers/helpers.php | 18 + src/Notifynder/Managers/NotifynderManager.php | 19 + src/Notifynder/Models/Notification.php | 212 +----- .../Models/NotificationCategory.php | 32 +- src/Notifynder/Models/NotificationGroup.php | 14 +- .../Models/NotifynderCollection.php | 80 --- src/Notifynder/Notifable.php | 151 ---- src/Notifynder/Notifications/ExtraParams.php | 168 ----- .../Notifications/NotificationManager.php | 278 -------- .../Notifications/NotificationRepository.php | 416 ----------- src/Notifynder/Notifynder.php | 320 --------- src/Notifynder/NotifynderManager.php | 652 ------------------ src/Notifynder/NotifynderServiceProvider.php | 290 +------- .../Parsers/ArtisanOptionsParser.php | 56 -- src/Notifynder/Parsers/NotifynderParser.php | 169 ----- src/Notifynder/Senders/SendGroup.php | 82 --- src/Notifynder/Senders/SendMultiple.php | 38 - src/Notifynder/Senders/SendOne.php | 60 -- src/Notifynder/Senders/SenderFactory.php | 120 ---- src/Notifynder/Senders/SenderManager.php | 199 ------ src/Notifynder/Traits/Notifable.php | 14 + src/Notifynder/Translator/Compiler.php | 97 --- .../Translator/TranslatorManager.php | 133 ---- src/config/notifynder.php | 2 +- tests/.gitkeep | 0 tests/TestCaseDB.php | 87 --- tests/factories/factories.php | 32 - tests/integration/CreateModels.php | 67 -- tests/integration/CustomSender.php | 42 -- tests/integration/Handler/NotifyEvent.php | 31 - .../Handler/NotifynderHandlerTest.php | 181 ----- tests/integration/Notifable/NotifableTest.php | 170 ----- .../Notifications/NotificationTest.php | 213 ------ .../Notifications/NotifynderTest.php | 138 ---- .../GroupCategoryReposutoryTest.php | 69 -- .../Repositories/GroupRepositoryTest.php | 67 -- .../NotificationCategoryDBTest.php | 96 --- .../NotificationRepositoryDBTest.php | 282 -------- tests/integration/Senders/SendersTest.php | 175 ----- .../integration/Translator/TranslatorTest.php | 37 - tests/integration/Translator/translations.php | 9 - .../2014_08_01_164248_create_users_table.php | 32 - tests/models/User.php | 12 - 99 files changed, 259 insertions(+), 9291 deletions(-) rename .travis.yml => .old.travis.yml (100%) create mode 100644 spec/.gitkeep delete mode 100755 spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php delete mode 100755 spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php delete mode 100755 spec/Fenos/Notifynder/Groups/GroupManagerSpec.php delete mode 100755 spec/Fenos/Notifynder/Handler/DispatcherSpec.php delete mode 100755 spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php delete mode 100755 spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php delete mode 100755 spec/Fenos/Notifynder/Senders/SendMultipleSpec.php delete mode 100755 spec/Fenos/Notifynder/Senders/SendOneSpec.php delete mode 100755 spec/Fenos/Notifynder/Senders/SenderFactorySpec.php delete mode 100755 spec/Fenos/Notifynder/Senders/SenderManagerSpec.php delete mode 100755 spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php delete mode 100755 src/Notifynder/Artisan/CreateCategory.php delete mode 100755 src/Notifynder/Artisan/CreateGroup.php delete mode 100755 src/Notifynder/Artisan/DeleteCategory.php delete mode 100755 src/Notifynder/Artisan/PushCategoryToGroup.php delete mode 100755 src/Notifynder/Builder/BuilderRules.php delete mode 100755 src/Notifynder/Builder/NotifynderBuilder.php delete mode 100755 src/Notifynder/Categories/CategoryManager.php delete mode 100755 src/Notifynder/Categories/CategoryRepository.php create mode 100644 src/Notifynder/Collections/Config.php delete mode 100755 src/Notifynder/Contracts/CategoryDB.php create mode 100644 src/Notifynder/Contracts/ConfigContract.php delete mode 100755 src/Notifynder/Contracts/DefaultSender.php delete mode 100755 src/Notifynder/Contracts/NotificationDB.php delete mode 100755 src/Notifynder/Contracts/NotifyListener.php delete mode 100755 src/Notifynder/Contracts/NotifynderCategory.php create mode 100755 src/Notifynder/Contracts/NotifynderContract.php delete mode 100755 src/Notifynder/Contracts/NotifynderDispatcher.php delete mode 100755 src/Notifynder/Contracts/NotifynderGroup.php delete mode 100755 src/Notifynder/Contracts/NotifynderGroupCategoryDB.php delete mode 100755 src/Notifynder/Contracts/NotifynderGroupDB.php delete mode 100755 src/Notifynder/Contracts/NotifynderNotification.php delete mode 100755 src/Notifynder/Contracts/NotifynderSender.php delete mode 100755 src/Notifynder/Contracts/NotifynderTranslator.php delete mode 100755 src/Notifynder/Contracts/Sender.php delete mode 100755 src/Notifynder/Contracts/StoreNotification.php delete mode 100755 src/Notifynder/Exceptions/CategoryNotFoundException.php delete mode 100644 src/Notifynder/Exceptions/EntityNotIterableException.php delete mode 100755 src/Notifynder/Exceptions/EntityNotSpecifiedException.php delete mode 100644 src/Notifynder/Exceptions/ExtraParamsException.php delete mode 100644 src/Notifynder/Exceptions/IterableIsEmptyException.php delete mode 100755 src/Notifynder/Exceptions/NotificationBuilderException.php delete mode 100755 src/Notifynder/Exceptions/NotificationLanguageNotFoundException.php delete mode 100755 src/Notifynder/Exceptions/NotificationNotFoundException.php delete mode 100755 src/Notifynder/Exceptions/NotificationTranslationNotFoundException.php delete mode 100755 src/Notifynder/Exceptions/NotifynderGroupNotFoundException.php delete mode 100755 src/Notifynder/Facades/Notifynder.php delete mode 100755 src/Notifynder/Groups/GroupCategoryRepository.php delete mode 100755 src/Notifynder/Groups/GroupManager.php delete mode 100755 src/Notifynder/Groups/GroupRepository.php delete mode 100755 src/Notifynder/Handler/Dispatcher.php delete mode 100755 src/Notifynder/Handler/NotifynderEvent.php delete mode 100755 src/Notifynder/Handler/NotifynderHandler.php create mode 100644 src/Notifynder/Helpers/helpers.php create mode 100755 src/Notifynder/Managers/NotifynderManager.php delete mode 100755 src/Notifynder/Models/NotifynderCollection.php delete mode 100755 src/Notifynder/Notifable.php delete mode 100644 src/Notifynder/Notifications/ExtraParams.php delete mode 100755 src/Notifynder/Notifications/NotificationManager.php delete mode 100755 src/Notifynder/Notifications/NotificationRepository.php delete mode 100755 src/Notifynder/Notifynder.php delete mode 100755 src/Notifynder/NotifynderManager.php delete mode 100755 src/Notifynder/Parsers/ArtisanOptionsParser.php delete mode 100755 src/Notifynder/Parsers/NotifynderParser.php delete mode 100755 src/Notifynder/Senders/SendGroup.php delete mode 100755 src/Notifynder/Senders/SendMultiple.php delete mode 100755 src/Notifynder/Senders/SendOne.php delete mode 100755 src/Notifynder/Senders/SenderFactory.php delete mode 100755 src/Notifynder/Senders/SenderManager.php create mode 100755 src/Notifynder/Traits/Notifable.php delete mode 100755 src/Notifynder/Translator/Compiler.php delete mode 100755 src/Notifynder/Translator/TranslatorManager.php create mode 100644 tests/.gitkeep delete mode 100755 tests/TestCaseDB.php delete mode 100755 tests/factories/factories.php delete mode 100755 tests/integration/CreateModels.php delete mode 100755 tests/integration/CustomSender.php delete mode 100755 tests/integration/Handler/NotifyEvent.php delete mode 100755 tests/integration/Handler/NotifynderHandlerTest.php delete mode 100755 tests/integration/Notifable/NotifableTest.php delete mode 100755 tests/integration/Notifications/NotificationTest.php delete mode 100755 tests/integration/Notifications/NotifynderTest.php delete mode 100755 tests/integration/Repositories/GroupCategoryReposutoryTest.php delete mode 100755 tests/integration/Repositories/GroupRepositoryTest.php delete mode 100755 tests/integration/Repositories/NotificationCategoryDBTest.php delete mode 100755 tests/integration/Repositories/NotificationRepositoryDBTest.php delete mode 100755 tests/integration/Senders/SendersTest.php delete mode 100755 tests/integration/Translator/TranslatorTest.php delete mode 100755 tests/integration/Translator/translations.php delete mode 100755 tests/migrations/2014_08_01_164248_create_users_table.php delete mode 100755 tests/models/User.php diff --git a/.travis.yml b/.old.travis.yml similarity index 100% rename from .travis.yml rename to .old.travis.yml diff --git a/composer.json b/composer.json index 13fd780..38cf645 100755 --- a/composer.json +++ b/composer.json @@ -28,7 +28,10 @@ ], "psr-4": { "Fenos\\Notifynder\\": "src/Notifynder" - } + }, + "files": [ + "app/Helpers/helpers.php" + ] }, "autoload-dev": { "classmap": [ diff --git a/spec/.gitkeep b/spec/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php b/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php deleted file mode 100755 index 8a40ba5..0000000 --- a/spec/Fenos/Notifynder/Builder/NotifynderBuilderSpec.php +++ /dev/null @@ -1,197 +0,0 @@ -beConstructedWith($category); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Builder\NotifynderBuilder'); - } - - /** @test */ - public function it_set_the_FROM_value_with_a_single_entity() - { - $user_id = 1; - - $this->from($user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_set_the_FROM_value_giving_a_polymorphic_entity() - { - $user_id = 1; - $user_class = 'User'; - - $this->from($user_class, $user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_set_the_FROM_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity() - { - $user_id = 1; - $user_class = 'User'; - - $this->shouldThrow('InvalidArgumentException')->during('from', [$user_id, $user_class]); - } - - /** @test */ - public function it_set_the_TO_value_with_a_single_entity() - { - $user_id = 1; - - $this->to($user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_set_the_TO_value_giving_a_polymorphic_entity() - { - $user_id = 1; - $user_class = 'User'; - - $this->to($user_class, $user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_set_the_TO_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity() - { - $user_id = 1; - $user_class = 'User'; - - $this->shouldThrow('InvalidArgumentException')->during('to', [$user_id, $user_class]); - } - - /** @test */ - public function it_add_the_url_parameter_to_the_builder() - { - $url = 'www.notifynder.io'; - - $this->url($url)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_allow_only_string_as_url() - { - $url = 1; - - $this->shouldThrow('InvalidArgumentException')->during('url', [$url]); - } - - /** @test */ - public function it_add_the_expire_parameter_to_the_builder() - { - date_default_timezone_set('UTC'); - - $datetime = new Carbon; - - $this->expire($datetime)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_allow_only_carbon_instance_as_expire_time() - { - $datetime = 1; - - $this->shouldThrow('InvalidArgumentException')->during('expire', [$datetime]); - } - - /** @test */ - public function it_add_a_category_id_to_the_builder() - { - $category_id = 1; - - $this->category($category_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_add_a_category_id_to_the_builder_givin_the_name_of_it(CategoryManager $category, NotificationCategory $categoryModel) - { - $name = 'category.name'; - $category_id = 1; - - $category->findByName($name)->shouldBeCalled() - ->willReturn($categoryModel); - - $categoryModel->getAttribute('id')->willReturn($category_id); - - $this->category($name)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_add_the_extra_parameter_to_the_builder() - { - $extra = ['my' => 'extra']; - - $this->extra($extra)->shouldReturnAnInstanceOf(NotifynderBuilder::class); - } - - /** @test */ - public function it_allow_only_associative_array_as_extra_parameter_they_llbe_converted_in_jon() - { - $extra = ['my']; - - $this->shouldThrow('InvalidArgumentException')->during('extra', [$extra]); - } - - /** @test */ - public function it_create_a_builder_array_using_a_raw_closure() - { - date_default_timezone_set('UTC'); - - $closure = function (NotifynderBuilder $builder) { - return $builder->to(1)->from(2)->url('notifynder.io')->category(1); - }; - - $this->raw($closure)->shouldHaveKey('to_id'); - $this->raw($closure)->shouldHaveKey('from_id'); - $this->raw($closure)->shouldHaveKey('url'); - $this->raw($closure)->shouldHaveKey('category_id'); - $this->raw($closure)->shouldHaveKey('created_at'); - $this->raw($closure)->shouldHaveKey('updated_at'); - } - - public function it_create_multi_notification_in_a_loop() - { - $closure = function (NotifynderBuilder $builder, $data, $key) { - return $builder->to(1)->from(2)->url('notifynder.io')->category(1); - }; - } - - public function it_create_empty_array_loop_builder() - { - $closure = function (NotifynderBuilder $builder, $data, $key) { - return $builder->to(1)->from(2)->url('notifynder.io')->category(1); - }; - $this->shouldThrow(IterableIsEmptyException::class)->during('loop', [[], $closure]); - } - - public function it_create_empty_collection_loop_builder() - { - $closure = function (NotifynderBuilder $builder, $data, $key) { - return $builder->to(1)->from(2)->url('notifynder.io')->category(1); - }; - $this->shouldThrow(IterableIsEmptyException::class)->during('loop', [new Collection([]), $closure]); - } - - public function it_create_not_iterable_loop_builder() - { - $closure = function (NotifynderBuilder $builder, $data, $key) { - return $builder->to(1)->from(2)->url('notifynder.io')->category(1); - }; - $this->shouldThrow(EntityNotIterableException::class)->during('loop', ['hello world', $closure]); - } -} diff --git a/spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php b/spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php deleted file mode 100755 index 0c9ca34..0000000 --- a/spec/Fenos/Notifynder/Categories/CategoryManagerSpec.php +++ /dev/null @@ -1,80 +0,0 @@ -shouldHaveType('Fenos\Notifynder\Categories\CategoryManager'); - } - - public function let(CategoryDB $categoryRepository) - { - $this->beConstructedWith($categoryRepository); - } - - /** @test */ - public function it_find_a_category_by_name(CategoryDB $categoryRepository) - { - $nameCategory = 'test.category'; - - $categoryRepository->findByName($nameCategory)->shouldBeCalled() - ->willReturn(new NotificationCategory()); - - $this->findByName($nameCategory)->shouldReturnAnInstanceOf(NotificationCategory::class); - } - - /** @test */ - public function it_try_to_find_a_non_existing_category(CategoryDB $categoryRepository) - { - $nameCategory = 'test.category'; - - $categoryRepository->findByName($nameCategory)->shouldBeCalled() - ->willReturn(null); - - $this->shouldThrow(CategoryNotFoundException::class) - ->during('findByName', [$nameCategory]); - } - - /** @test */ - public function it_store_a_category(CategoryDB $categoryRepository) - { - $categoryName = 'hello'; - $categoryText = 'wow'; - - $categoryRepository->add($categoryName, $categoryText)->shouldBeCalled() - ->willReturn(new NotificationCategory()); - - $this->add($categoryName, $categoryText)->shouldReturnAnInstanceOf(NotificationCategory::class); - } - - /** @test */ - public function it_delete_a_category_by_id(CategoryDB $categoryRepository) - { - $categoryId = 1; - - $categoryRepository->delete($categoryId); - - $categoryRepository->delete($categoryId)->shouldBeCalled() - ->willReturn(1); - - $this->delete($categoryId)->shouldReturn(1); - } - - /** @test */ - public function it_delete_a_category_by_name(CategoryDB $categoryRepository) - { - $categoryName = 'testCategory'; - - $categoryRepository->deleteByName($categoryName)->shouldBeCalled() - ->willReturn(1); - - $this->deleteByName($categoryName)->shouldReturn(1); - } -} diff --git a/spec/Fenos/Notifynder/Groups/GroupManagerSpec.php b/spec/Fenos/Notifynder/Groups/GroupManagerSpec.php deleted file mode 100755 index d451d4f..0000000 --- a/spec/Fenos/Notifynder/Groups/GroupManagerSpec.php +++ /dev/null @@ -1,123 +0,0 @@ -beConstructedWith($groupDB, $groupCategoryDB); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Groups\GroupManager'); - } - - /** @test */ - public function it_find_a_group_by_id(NotifynderGroupDB $groupDB, NotificationGroup $group) - { - $group_id = 1; - - $groupDB->find($group_id)->shouldBeCalled() - ->willReturn($group); - - $this->findById($group_id)->shouldReturnAnInstanceOf(NotificationGroup::class); - } - - /** @test */ - public function it_try_to_find_an_not_existing_group_by_id(NotifynderGroupDB $groupDB) - { - $group_id = 1; - - $groupDB->find($group_id)->shouldBeCalled() - ->willReturn(null); - - $this->shouldThrow(NotifynderGroupNotFoundException::class)->during('findById', [$group_id]); - } - - /** @test */ - public function it_find_a_group_by_name(NotifynderGroupDB $groupDB, NotificationGroup $group) - { - $group_name = 'mygroup'; - - $groupDB->findByName($group_name)->shouldBeCalled() - ->willReturn($group); - - $this->findByName($group_name)->shouldReturnAnInstanceOf(NotificationGroup::class); - } - - /** @test */ - public function it_try_to_find_an_not_existing_group_by_name(NotifynderGroupDB $groupDB) - { - $group_name = 'mygroup'; - - $groupDB->findByName($group_name)->shouldBeCalled() - ->willReturn(null); - - $this->shouldThrow(NotifynderGroupNotFoundException::class)->during('findByName', [$group_name]); - } - - /** @test */ - public function it_add_a_category_to_a_group_by_id(NotifynderGroupCategoryDB $groupCategoryDB, NotificationGroup $group) - { - $group_id = 1; - $category_id = 2; - - $groupCategoryDB->addCategoryToGroupById($group_id, $category_id)->shouldBeCalled() - ->willReturn($group); - - $this->addCategoryToGroupById($group_id, $category_id)->shouldReturnAnInstanceOf(NotificationGroup::class); - } - - /** @test */ - public function it_add_a_category_to_a_group_by_name(NotifynderGroupCategoryDB $groupCategoryDB, NotificationGroup $group) - { - $group_name = 'mygroup'; - $category_name = 'mycategory'; - - $groupCategoryDB->addCategoryToGroupByName($group_name, $category_name)->shouldBeCalled() - ->willReturn($group); - - $this->addCategoryToGroupByName($group_name, $category_name)->shouldReturnAnInstanceOf(NotificationGroup::class); - } - - /** @test */ - public function it_add_multiple_categories_to_a_group(NotifynderGroupCategoryDB $groupCategoryDB) - { - $group_name = 'mygroup'; - $category1 = 'mycategory1'; - $category2 = 'mycategory2'; - - $groupCategoryDB->addMultipleCategoriesToGroup($group_name, [$category1, $category2])->shouldBeCalled() - ->willReturn(2); - - $this->addMultipleCategoriesToGroup($group_name, $category1, $category2) - ->shouldReturn(2); - } - - /** @test */ - public function it_add_a_group_in_the_db_respecting_convention(NotifynderGroupDB $groupDB, NotificationGroup $group) - { - $name = 'my.category'; - - $groupDB->create($name)->shouldBeCalled() - ->willReturn($group); - - $this->addGroup($name)->shouldReturnAnInstanceOf(NotificationGroup::class); - } - - /** @test */ - public function it_add_a_group_in_the_db_NOT_respecting_convention(NotifynderGroupDB $groupDB, NotificationGroup $group) - { - $name = 'mycategory'; // no dot as 'namespace' - - $this->shouldThrow('InvalidArgumentException')->during('addGroup', [$name]); - } -} diff --git a/spec/Fenos/Notifynder/Handler/DispatcherSpec.php b/spec/Fenos/Notifynder/Handler/DispatcherSpec.php deleted file mode 100755 index 3bd1f92..0000000 --- a/spec/Fenos/Notifynder/Handler/DispatcherSpec.php +++ /dev/null @@ -1,60 +0,0 @@ -beConstructedWith($dispatcher); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Handler\Dispatcher'); - } - - /** @test */ - public function it_fire_a_notifynder_event(Dispatcher $dispatcher, NotifynderManager $notifynder) - { - $key = 'event'; - $category = 'hello'; - $extraValues = []; - $notifyEvent = 'Notifynder.'.$key; - $notificationBuilt = [ - 0 => ['notification'], - ]; - - $notifynderEvent = new NotifynderEvent($notifyEvent, $category, $extraValues); - - $dispatcher->fire($notifyEvent, [$notifynderEvent, $notifynder])->shouldBeCalled() - ->willReturn($notificationBuilt); - - $notifynder->send($notificationBuilt[0])->shouldBeCalled() - ->willReturn(1); - - $this->fire($notifynder, $key, $category, $extraValues)->shouldReturn(1); - } - - /** @test */ - public function it_fire_a_notifynder_event_having_nothing_to_send(Dispatcher $dispatcher, NotifynderManager $notifynder) - { - $key = 'event'; - $category = 'hello'; - $extraValues = []; - $notifyEvent = 'Notifynder.'.$key; - - $notifynderEvent = new NotifynderEvent($notifyEvent, $category, $extraValues); - - $dispatcher->fire($notifyEvent, [$notifynderEvent, $notifynder])->shouldBeCalled() - ->willReturn(null); - - $this->fire($notifynder, $key, $category, $extraValues) - ->shouldReturn(null); - } -} diff --git a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php b/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php deleted file mode 100755 index 6a510eb..0000000 --- a/spec/Fenos/Notifynder/Notifications/NotificationManagerSpec.php +++ /dev/null @@ -1,220 +0,0 @@ -beConstructedWith($notificationRepo); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Notifications\NotificationManager'); - } - - /** @test */ - public function it_find_a_notification_by_id(NotificationDB $notificationRepo) - { - $notification_id = 1; - $notification = new Notification(); - - $notificationRepo->find($notification_id)->shouldBeCalled() - ->willReturn($notification); - - $this->find($notification_id)->shouldReturnAnInstanceOf(Notification::class); - } - - /** @test */ - public function it_try_to_find_an_inexistent_notification(NotificationDB $notificationRepo) - { - $notification_id = 1; - - $notificationRepo->find($notification_id)->shouldBeCalled() - ->willReturn(null); - - $this->shouldThrow(NotificationNotFoundException::class)->during('find', [$notification_id]); - } - - /** @test */ - public function it_read_one_notification_by_id(NotificationDB $notificationRepo) - { - $notification_id = 1; - $notification = new Notification(); - - $notificationRepo->find($notification_id)->shouldBeCalled() - ->willReturn($notification); - - $notificationRepo->readOne($notification)->shouldBeCalled() - ->willReturn($notification); - - $this->readOne($notification_id)->shouldReturnAnInstanceOf($notification); - } - - /** @test */ - public function it_read_notifications_limit_to_a_given_number(NotificationDB $notificationRepo) - { - $to_id = 1; - $numbers = 5; - $order = 'asc'; - - $notificationRepo->readLimit($to_id, null, $numbers, $order)->shouldBeCalled() - ->willReturn($numbers); - - $this->readLimit($to_id, $numbers, $order)->shouldReturn($numbers); - } - - /** @test */ - public function it_read_all_notification_of_the_given_entity(NotificationDB $notificationRepo) - { - $id = 1; - $entity = null; - $notificationDeleted = 10; - - $notificationRepo->readAll($id, $entity)->shouldBeCalled() - ->willReturn($notificationDeleted); - - $this->readAll($id)->shouldReturn($notificationDeleted); - } - - /** @test */ - public function it_delete_a_notification_by_id(NotificationDB $notificationRepo) - { - $notification_id = 1; - - $notificationRepo->delete($notification_id)->shouldBeCalled() - ->willReturn(1); - - $this->delete($notification_id)->shouldReturn(1); - } - - /** @test */ - public function it_delete_notification_limiting_the_number_of_the_given_entity(NotificationDB $notificationRepo) - { - $entity_id = 1; - $numberLimit = 5; - $order = 'asc'; - - $notificationRepo->deleteLimit($entity_id, null, $numberLimit, $order)->shouldBeCalled() - ->willReturn($numberLimit); - - $this->deleteLimit($entity_id, $numberLimit, $order)->shouldReturn($numberLimit); - } - - /** @test */ - public function it_delete_all_notification_of_the_given_entity(NotificationDB $notificationRepo) - { - $entity_id = 1; - $notificationsDeleted = 10; - - $notificationRepo->deleteAll($entity_id, null)->shouldBeCalled() - ->willReturn($notificationsDeleted); - - $this->deleteAll($entity_id)->shouldReturn($notificationsDeleted); - } - - /** @test */ - public function it_get_not_read_notification(NotificationDB $notificationRepo, NotifynderCollection $collection) - { - $entity_id = 1; - $limit = 10; - $paginate = null; - - $notificationRepo->getNotRead($entity_id, null, $limit, $paginate, 'desc', null)->shouldBeCalled() - ->willReturn($collection); - - $collection->parse()->shouldBeCalled()->willReturn([]); - - $this->getNotRead($entity_id, $limit, $paginate, 'desc')->shouldReturn([]); - } - - /** @test */ - public function it_get_all_notifications_of_the_given_entity(NotificationDB $notificationRepo, NotifynderCollection $collection) - { - $entity_id = 1; - $limit = 10; - $paginate = null; - - $notificationRepo->getAll($entity_id, null, $limit, $paginate, 'desc', null)->shouldBeCalled() - ->willReturn($collection); - - $collection->parse()->shouldBeCalled()->willReturn([]); - - $this->getAll($entity_id, $limit, $paginate)->shouldReturn([]); - } - - /** @test */ - public function it_get_last_notification_of_the_current_entity(NotificationDB $notificationRepo) - { - $id = 1; - - $notificationRepo->getLastNotification($id, null, null)->shouldBeCalled()->willReturn(new Notification()); - - $this->getLastNotification($id)->shouldReturnAnInstanceOf(Notification::class); - } - - /** @test */ - public function it_get_last_notification_of_the_current_entity_filtering_by_category(NotificationDB $notificationRepo) - { - $id = 1; - $category = 'notifynder.category'; - - $notificationRepo->getLastNotificationByCategory($category, $id, null, null)->shouldBeCalled()->willReturn(new Notification()); - - $this->getLastNotificationByCategory($category, $id)->shouldReturnAnInstanceOf(Notification::class); - } - - /** @test */ - public function it_send_a_single_notification(NotificationDB $notificationRepo) - { - $notificationData = []; - $notification = new Notification(); - - $notificationRepo->storeSingle($notificationData)->shouldBeCalled() - ->willReturn($notification); - - $this->sendOne($notificationData)->shouldReturnAnInstanceOf(Notification::class); - } - - /** @test */ - public function it_send_multiple_notification(NotificationDB $notificationRepo) - { - $notificationData = []; - $notificationsSent = 5; - - $notificationRepo->storeMultiple($notificationData)->shouldBeCalled() - ->willReturn($notificationsSent); - - $this->sendMultiple($notificationData)->shouldReturn($notificationsSent); - } - - /** @test */ - public function it_count_notification_not_read(NotificationDB $notificationRepo) - { - $entity_id = 1; - $notificationCount = 10; - - $notificationRepo->countNotRead($entity_id, null, null)->shouldBeCalled() - ->willReturn($notificationCount); - - $this->countNotRead($entity_id)->shouldReturn($notificationCount); - } - - /** @test */ - public function it_delete_notification_by_categories(NotificationDB $notificationRepo) - { - $categoryName = 'notifynder.test'; - - $notificationRepo->deleteByCategory($categoryName, false)->shouldBeCalled() - ->willReturn(1); - - $this->deleteByCategory($categoryName)->shouldReturn(1); - } -} diff --git a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php b/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php deleted file mode 100755 index 79c31c4..0000000 --- a/spec/Fenos/Notifynder/Parsers/NotifynderParserSpec.php +++ /dev/null @@ -1,126 +0,0 @@ -shouldHaveType('Fenos\Notifynder\Parsers\NotifynderParser'); - } - - /** @test */ - public function it_should_replace_special_values_with_an_associative_array() - { - $extra = ['hello' => 'world']; - - $notification = [ - 'body' => [ - 'text' => 'Hi jhon hello {extra.hello}', - ], - 'extra' => json_encode($extra), - ]; - - $this->parse($notification)->shouldReturn('Hi jhon hello world'); - } - - /** @test */ - public function it_replace_from_values_relations() - { - $notification = [ - 'body' => [ - 'text' => 'Hi {to.username} hello', - ], - 'to' => [ - 'username' => 'jhon', - ], - 'extra' => null, - ]; - - $this->parse($notification)->shouldReturn('Hi jhon hello'); - } - - /** @test */ - public function it_replace_both_in_a_string() - { - $extra = ['hello' => 'world']; - - $notification = [ - 'body' => [ - 'text' => 'Hi {to.username} hello {extra.hello}', - ], - 'to' => [ - 'username' => 'jhon', - ], - 'extra' => json_encode($extra), - ]; - - $this->parse($notification)->shouldReturn('Hi jhon hello world'); - } - - /** @test */ - public function it_will_remove_extra_markup_if_extra_value_is_not_provided() - { - $extra = []; - - $notification = [ - 'body' => [ - 'text' => 'Hi {to.username} hello {extra.hello}', - ], - 'to' => [ - 'username' => 'jhon', - ], - 'extra' => json_encode($extra), - ]; - - // note the space, TODO: shall i remove it? - $this->parse($notification)->shouldReturn('Hi jhon hello '); - } - - /** @test */ - public function it_will_throw_exception_when_strict_extra_is_enabled() - { - $extra = null; - - $notification = [ - 'body' => [ - 'text' => 'Hi {to.username} hello {extra.hello}', - ], - 'to' => [ - 'username' => 'jhon', - ], - 'extra' => json_encode($extra), - ]; - - NotifynderParser::setStrictExtra(true); - - $this->shouldThrow(ExtraParamsException::class) - ->during('parse', [$notification]); - } - - /** @test */ - public function it_will_parse_4_extra_params() - { - $extra = [ - 'name' => 'fabri', - 'username' => 'fenos', - 'status' => 'active', - 'prof' => 'dev', - ]; - - $text = 'Hi {extra.name}, your username is: {extra.username} your status: {extra.status} your profession: {extra.prof}'; - $notification = [ - 'body' => [ - 'text' => $text, - ], - 'extra' => json_encode($extra), - ]; - - $parsedText = "Hi {$extra['name']}, your username is: {$extra['username']} your status: {$extra['status']} your profession: {$extra['prof']}"; - $this->parse($notification)->shouldReturn($parsedText); - } -} diff --git a/spec/Fenos/Notifynder/Senders/SendMultipleSpec.php b/spec/Fenos/Notifynder/Senders/SendMultipleSpec.php deleted file mode 100755 index df1938f..0000000 --- a/spec/Fenos/Notifynder/Senders/SendMultipleSpec.php +++ /dev/null @@ -1,32 +0,0 @@ -beConstructedWith($notifications); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Senders\SendMultiple'); - } - - /** @test */ - public function it_send_multiple_notification(StoreNotification $storeNotification) - { - $multiple = [ - ]; - - $storeNotification->storeMultiple($multiple)->shouldBeCalled() - ->willReturn(1); - - $this->send($storeNotification)->shouldReturn(1); - } -} diff --git a/spec/Fenos/Notifynder/Senders/SendOneSpec.php b/spec/Fenos/Notifynder/Senders/SendOneSpec.php deleted file mode 100755 index 26085a0..0000000 --- a/spec/Fenos/Notifynder/Senders/SendOneSpec.php +++ /dev/null @@ -1,45 +0,0 @@ -beConstructedWith($infoNotification); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Senders\SendOne'); - } - - /** @test */ - public function it_send_a_single_notification_having_the_category_(StoreNotification $storeNotification) - { - $infoNotification = [ - 'category_id' => 1, - ]; - - $this->beConstructedWith($infoNotification); - - $storeNotification->storeSingle($infoNotification)->shouldBeCalled() - ->willReturn(new Notification()); - - $this->send($storeNotification)->shouldReturnAnInstanceOf(Notification::class); - } - - /** @test */ - public function it_try_to_send_a_notification_without_category_id(StoreNotification $storeNotification) - { - // throw exception because I didn't specified a category_id - $this->shouldThrow(CategoryNotFoundException::class) - ->during('send', [$storeNotification]); - } -} diff --git a/spec/Fenos/Notifynder/Senders/SenderFactorySpec.php b/spec/Fenos/Notifynder/Senders/SenderFactorySpec.php deleted file mode 100755 index c55f7e8..0000000 --- a/spec/Fenos/Notifynder/Senders/SenderFactorySpec.php +++ /dev/null @@ -1,56 +0,0 @@ -beConstructedWith($notifynderGroup, $notifynderCategory); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Senders\SenderFactory'); - } - - /** @test */ - public function it_get_a_dynamic_sender_checking_array_type_GET_SINGLE() - { - // if the array is multidimensional then - // send multiple - $notification = []; - $category = 1; - - $this->getSender($notification, $category)->shouldReturnAnInstanceOf(SendOne::class); - } - - /** @test */ - public function it_get_a_dynamic_sender_checking_array_type_GET_MULTIPLE() - { - // if the array is multidimensional then - // send multiple - $notification = [ - 0 => [], - ]; - $category = 1; - - $this->getSender($notification, $category)->shouldReturnAnInstanceOf(SendMultiple::class); - } - - /** @test */ - public function it_get_the_send_group_sender() - { - $group_name = 'mygroup'; - $info = []; - - $this->sendGroup($group_name, $info)->shouldReturnAnInstanceOf(SendGroup::class); - } -} diff --git a/spec/Fenos/Notifynder/Senders/SenderManagerSpec.php b/spec/Fenos/Notifynder/Senders/SenderManagerSpec.php deleted file mode 100755 index 744c085..0000000 --- a/spec/Fenos/Notifynder/Senders/SenderManagerSpec.php +++ /dev/null @@ -1,114 +0,0 @@ -beConstructedWith($senderFactory, $storeNotification, $application); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Senders\SenderManager'); - } - - /** @test */ - public function it_send_now_a_notification(SenderFactory $senderFactory, - DefaultSender $sender, - StoreNotification $storeNotification) - { - $notifications = []; - $category = 1; - - $senderFactory->getSender($notifications, $category)->shouldBeCalled() - ->willReturn($sender); - - $sender->send($storeNotification)->shouldBeCalled() - ->willReturn(1); - - $this->sendNow($notifications, $category)->shouldReturn(1); - } - - /** @test */ - public function it_send_one_notification(SenderFactory $senderFactory, - DefaultSender $sender, - StoreNotification $storeNotification) - { - $notifications = []; - $category = 1; - - $senderFactory->sendSingle($notifications, $category)->shouldBeCalled() - ->willReturn($sender); - - $sender->send($storeNotification, $category)->shouldBeCalled() - ->willReturn(1); - - $this->sendOne($notifications, $category)->shouldReturn(1); - } - - /** @test */ - public function it_send_multiple_notification(SenderFactory $senderFactory, - DefaultSender $sender, - StoreNotification $storeNotification) - { - $notifications = []; - - $senderFactory->sendMultiple($notifications)->shouldBeCalled() - ->willReturn($sender); - - $sender->send($storeNotification)->shouldBeCalled() - ->willReturn(1); - - $this->sendMultiple($notifications)->shouldReturn(1); - } - - /** @test */ - public function it_call_an_extended_method(SenderFactory $senderFactory, - DefaultSender $sender, - StoreNotification $storeNotification) - { - $notifications = []; - - $this->extend('sendExtended', function ($app) use ($sender) { - return new TestExtender(); - }); - - $this->sendExtended($notifications)->shouldReturn([]); - } - - /** @test */ - public function it_try_to_call_an_inexistent_extended_method() - { - $this->shouldThrow(BadMethodCallException::class)->during('NotExistingExtender', []); - } -} - -/* -|-------------------------------------------------------------------------- -| Extended class -|-------------------------------------------------------------------------- -| Test Extender sender class ---------------------------------------------------------------------------*/ - -class TestExtender implements DefaultSender -{ - /** - * Send Single notification. - * - * @param StoreNotification $sender - * @return mixed - */ - public function send(StoreNotification $sender) - { - return []; - } -} diff --git a/spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php b/spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php deleted file mode 100755 index a16d877..0000000 --- a/spec/Fenos/Notifynder/Translator/TranslatorManagerSpec.php +++ /dev/null @@ -1,128 +0,0 @@ -beConstructedWith($compiler, $config); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Fenos\Notifynder\Translator\TranslatorManager'); - } - - /** @test */ - public function it_translate_the_given_category_in_the_given_language(Compiler $compiler, Repository $config) - { - $filePath = 'cached/file'; - $categoryToTranslate = 'categoryName'; - $translations = [ - 'it' => [ - $categoryToTranslate => 'translation', - ], - ]; - - $compiler->getFilePath()->shouldBeCalled() - ->willReturn($filePath); - - $config->get('notifynder.translations')->shouldBeCalled() - ->willReturn($translations); - - $compiler->cacheFile($translations)->shouldBeCalled(); - - $this->translate('it', $categoryToTranslate) - ->shouldReturn($translations['it'][$categoryToTranslate]); - } - - /** @test */ - public function it__try_to_translate_the_given_category(Compiler $compiler, Repository $config) - { - $filePath = 'cached/file'; - $categoryToTranslate = 'categoryName'; - $translations = [ - 'it' => [ - $categoryToTranslate => 'translation', - ], - ]; - - $compiler->getFilePath()->shouldBeCalled() - ->willReturn($filePath); - - $config->get('notifynder.translations')->shouldBeCalled() - ->willReturn($translations); - - $compiler->cacheFile($translations)->shouldBeCalled(); - - $this->shouldThrow(NotificationTranslationNotFoundException::class) - ->during('translate', ['it', 'not existing']); - } - - /** @test */ - public function it_get_a_language_from_the_translations(Compiler $compiler, Repository $config) - { - $filePath = 'cached/file'; - $translations = [ - 'it' => [ - 'categoryName' => 'translation', - ], - ]; - - $compiler->getFilePath()->shouldBeCalled() - ->willReturn($filePath); - - $config->get('notifynder.translations')->shouldBeCalled() - ->willReturn($translations); - - $compiler->cacheFile($translations)->shouldBeCalled(); - - $this->getLanguage('it')->shouldReturn($translations['it']); - } - - /** @test */ - public function it__try_to_get_a_language_from_the_translations(Compiler $compiler, Repository $config) - { - $filePath = 'cached/file'; - $translations = [ - 'it' => [ - 'categoryName' => 'translation', - ], - ]; - - $compiler->getFilePath()->shouldBeCalled() - ->willReturn($filePath); - - $config->get('notifynder.translations')->shouldBeCalled() - ->willReturn($translations); - - $compiler->cacheFile($translations)->shouldBeCalled(); - - $this->shouldThrow(NotificationLanguageNotFoundException::class) - ->during('getLanguage', ['en']); - } - - /** @test */ - public function it_get_the_translations_from_never_cached_config_file(Compiler $compiler, Repository $config) - { - $filePath = 'cached/file'; - $translations = []; - - $compiler->getFilePath()->shouldBeCalled() - ->willReturn($filePath); - - $config->get('notifynder.translations')->shouldBeCalled() - ->willReturn($translations); - - $compiler->cacheFile($translations)->shouldBeCalled(); - - $this->getTranslations()->shouldReturn($translations); - } -} diff --git a/src/Notifynder/Artisan/CreateCategory.php b/src/Notifynder/Artisan/CreateCategory.php deleted file mode 100755 index 0fad1bb..0000000 --- a/src/Notifynder/Artisan/CreateCategory.php +++ /dev/null @@ -1,76 +0,0 @@ -notifynderCategory = $notifynderCategory; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function fire() - { - $name = $this->argument('name'); - $text = $this->argument('text'); - - $createCategory = $this->notifynderCategory->add($name, $text); - - if (! $createCategory) { - $this->error('The category has been not created'); - - return false; - } - - $this->info("Category $createCategory->name has been created"); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['name', InputArgument::REQUIRED, 'Name of the category.'], - ['text', InputArgument::REQUIRED, 'Text of the category.'], - ]; - } -} diff --git a/src/Notifynder/Artisan/CreateGroup.php b/src/Notifynder/Artisan/CreateGroup.php deleted file mode 100755 index d947478..0000000 --- a/src/Notifynder/Artisan/CreateGroup.php +++ /dev/null @@ -1,70 +0,0 @@ -notifynderGroup = $notifynderGroup; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function fire() - { - $nameGroup = $this->argument('name'); - - if (! $this->notifynderGroup->addGroup($nameGroup)) { - $this->error('The name must be a string with dots as namespaces'); - - return false; - } - $this->info("Group {$nameGroup} has Been created"); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['name', InputArgument::REQUIRED, 'user.post.add'], - ]; - } -} diff --git a/src/Notifynder/Artisan/DeleteCategory.php b/src/Notifynder/Artisan/DeleteCategory.php deleted file mode 100755 index 97fd09d..0000000 --- a/src/Notifynder/Artisan/DeleteCategory.php +++ /dev/null @@ -1,81 +0,0 @@ -notifynderCategory = $notifynderCategory; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function fire() - { - $identifier = $this->argument('identifier'); - - if ($this->isIntegerValue($identifier)) { - $delete = $this->notifynderCategory->delete($identifier); - } else { - $delete = $this->notifynderCategory->deleteByName($identifier); - } - - if (! $delete) { - $this->error('Category Not found'); - - return false; - } - $this->info('Category has been deleted'); - } - - public function isIntegerValue($identifier) - { - return preg_match('/[0-9]/', $identifier); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['identifier', InputArgument::REQUIRED, '1 - nameCategory'], - ]; - } -} diff --git a/src/Notifynder/Artisan/PushCategoryToGroup.php b/src/Notifynder/Artisan/PushCategoryToGroup.php deleted file mode 100755 index 416c868..0000000 --- a/src/Notifynder/Artisan/PushCategoryToGroup.php +++ /dev/null @@ -1,116 +0,0 @@ -notifynderGroup = $notifynderGroup; - $this->artisanOptionsParser = $artisanOptionsParser; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function fire() - { - $arguments = $this->getArgumentsConsole(); - - $categoryGroup = array_shift($arguments); - $arguments = $arguments[0]; - $categories = explode(',', $arguments); - - $groupCategories = $this->notifynderGroup - ->addMultipleCategoriesToGroup($categoryGroup, $categories); - - if ($groupCategories) { - foreach ($groupCategories->categories as $category) { - $this->info("Category {$category->name} has been associated to the group {$groupCategories->name}"); - } - } else { - $this->error('The name must be a string with dots as namespaces'); - } - } - - /** - * @return array|string - */ - public function getArgumentsConsole() - { - $names = $this->argument('name'); - - $categories = $this->option('categories'); - - $categories = $this->artisanOptionsParser->parse($categories); - - array_unshift($categories, $names); - - return $categories; - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['name', InputArgument::REQUIRED, 'user.post.add'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['categories', null, InputOption::VALUE_OPTIONAL, 'notifynder.name', []], - ]; - } -} diff --git a/src/Notifynder/Builder/BuilderRules.php b/src/Notifynder/Builder/BuilderRules.php deleted file mode 100755 index ae38e4a..0000000 --- a/src/Notifynder/Builder/BuilderRules.php +++ /dev/null @@ -1,159 +0,0 @@ -config instanceof Repository) { - $customRequiredFields = $this->config->get('notifynder.additional_fields.required', []); - } - - return array_unique($this->requiredFields + $customRequiredFields); - } - - /** - * Check that the builder has - * the required field to send the - * notifications correctly. - * - * @param $array - * @return bool - */ - public function hasRequiredFields($array) - { - foreach ($this->getRequiredFields() as $field) { - if (! array_key_exists($field, $array)) { - return false; - } - } - - return true; - } - - /** - * Check if is a required field. - * - * @param $offset - * @return bool - */ - public function isRequiredField($offset) - { - return in_array($offset, $this->getRequiredFields()); - } - - /** - * Check if the array passed is - * multidimensional. - * - * @param $arr - * @return bool - */ - protected function isReadyArrToFormatInJson(array $arr) - { - if ($this->isAssociativeArr($arr)) { - return true; - } - - if (count($arr) > 0) { - $error = "The 'extra' value must to be an associative array"; - throw new InvalidArgumentException($error); - } - - return false; - } - - /** - * @param array $arr - * @return bool - */ - protected function isAssociativeArr(array $arr) - { - return array_keys($arr) !== range(0, count($arr) - 1); - } - - /** - * Check if the array is - * multidimensional. - * - * @param $arr - * @return bool - */ - public function isMultidimensionalArray($arr) - { - $rv = array_filter($arr, 'is_array'); - if (count($rv) > 0) { - return true; - } - - return false; - } -} diff --git a/src/Notifynder/Builder/NotifynderBuilder.php b/src/Notifynder/Builder/NotifynderBuilder.php deleted file mode 100755 index cf7109a..0000000 --- a/src/Notifynder/Builder/NotifynderBuilder.php +++ /dev/null @@ -1,383 +0,0 @@ -notifynderCategory = $notifynderCategory; - } - - /** - * Set who will send the notification. - * - * @return $this - */ - public function from() - { - $from = func_get_args(); - - $this->setEntityAction($from, 'from'); - - return $this; - } - - /** - * Set who will receive the notification. - * - * @return $this - */ - public function to() - { - $from = func_get_args(); - - $this->setEntityAction($from, 'to'); - - return $this; - } - - /** - * Set the url of the notification. - * - * @param $url - * @return $this - */ - public function url($url) - { - $this->isString($url); - - $this->setBuilderData('url', $url); - - return $this; - } - - /** - * Set expire time. - * - * @param $datetime - * @return $this - */ - public function expire($datetime) - { - $this->isCarbon($datetime); - $this->setBuilderData('expire_time', $datetime); - - return $this; - } - - /** - * Set Category and covert it, to the id - * if name of it given. - * - * @param $category - * @return $this - */ - public function category($category) - { - if (! is_numeric($category)) { - $category = $this->notifynderCategory - ->findByName($category)->id; - } - - $this->setBuilderData('category_id', $category); - - return $this; - } - - /** - * Set extra value. - * - * @param $extra - * @return $this - */ - public function extra(array $extra = []) - { - $this->isReadyArrToFormatInJson($extra); - - $jsonExtraValues = json_encode($extra); - - $this->setBuilderData('extra', $jsonExtraValues); - - return $this; - } - - /** - * Build the array with the builder inside - * a Closure, it has more flexibility for - * the generation of your array. - * - * - * @param callable|Closure $closure - * @return array|false - * @throws NotificationBuilderException - */ - public function raw(Closure $closure) - { - $builder = $closure($this); - - if (! is_null($builder)) { - return $this->toArray(); - } - - return false; - } - - /** - * Loop the data for create - * multi notifications array. - * - * @param $dataToIterate - * @param Closure $builder - * @return $this - * @throws \Fenos\Notifynder\Exceptions\IterableIsEmptyException - * @throws \Fenos\Notifynder\Exceptions\EntityNotIterableException - */ - public function loop($dataToIterate, Closure $builder) - { - if (! $this->isIterable($dataToIterate)) { - throw new EntityNotIterableException('The data passed must be iterable'); - } - if (count($dataToIterate) <= 0) { - throw new IterableIsEmptyException('The Iterable passed must contain at least one element'); - } - - $notifications = []; - - $newBuilder = new self($this->notifynderCategory); - - foreach ($dataToIterate as $key => $data) { - $builder($newBuilder, $data, $key); - $notifications[] = $newBuilder->toArray(); - } - - $this->notifications = $notifications; - - return $this; - } - - /** - * Compose the builder to - * the array. - * - * @throws NotificationBuilderException - * @return mixed - */ - public function toArray() - { - $hasMultipleNotifications = $this->isMultidimensionalArray($this->notifications); - - // If the builder is handling a single notification - // we will validate only it - if (! $hasMultipleNotifications) { - $this->setDate(); - - if ($this->hasRequiredFields($this->notifications)) { - return $this->notifications; - } - } - - // If has multiple Notifications - // we will validate one by one - if ($hasMultipleNotifications) { - $allow = []; - - foreach ($this->notifications as $index => $notification) { - $allow[$index] = $this->hasRequiredFields($notification); - } - - if (! in_array(false, $allow)) { - return $this->notifications; - } - } - - $error = 'The fields: '.implode(',', $this->getRequiredFields()).' are required'; - throw new NotificationBuilderException($error); - } - - /** - * Refresh the state of the notifications. - */ - public function refresh() - { - $this->notifications = []; - - return $this; - } - - /** - * @param $var - * @return bool - */ - protected function isIterable($var) - { - return is_array($var) || $var instanceof Traversable; - } - - /** - * It set the entity who will do - * the action of receive or - * send. - * - * @param $from - * @param $property - * @return array - */ - protected function setEntityAction($from, $property) - { - // Check if has the entity as parameter - // it should be the firstOne - if ($this->hasEntity($from)) { - $this->isString($from[0]); - $this->isNumeric($from[1]); - - $this->setBuilderData("{$property}_type", $from[0]); - $this->setBuilderData("{$property}_id", $from[1]); - } elseif ($from[0] instanceof Model) { - $this->setBuilderData("{$property}_type", $from[0]->getMorphClass()); - $this->setBuilderData("{$property}_id", $from[0]->getKey()); - } else { - $this->isNumeric($from[0]); - $this->setBuilderData("{$property}_id", $from[0]); - } - } - - /** - * If the values passed are 2 or more, - * it means that you specified the entity - * over then the id. - * - * @param array $info - * @return bool - */ - protected function hasEntity(array $info) - { - return count($info) >= 2; - } - - /** - * Set date on the array. - */ - protected function setDate() - { - $this->date = $data = Carbon::now(); - - $this->setBuilderData('updated_at', $data); - $this->setBuilderData('created_at', $data); - } - - /** - * @return string - */ - protected function getDate() - { - return $this->date; - } - - /** - * Set builder Data. - * - * @param $field - * @param $data - */ - public function setBuilderData($field, $data) - { - return $this->notifications[$field] = $data; - } - - /** - * @param mixed $offset - * @return bool - */ - public function offsetExists($offset) - { - return array_key_exists($offset, $this->notifications); - } - - /** - * @param mixed $offset - * @return mixed - */ - public function offsetGet($offset) - { - return $this->notifications[$offset]; - } - - /** - * @param mixed $offset - * @param mixed $value - */ - public function offsetSet($offset, $value) - { - if (method_exists($this, $offset)) { - return $this->{$offset}($value); - } - - if ($this->isRequiredField($offset)) { - $this->notifications[$offset] = $value; - } - } - - /** - * @param Repository $config - */ - public function setConfig(Repository $config) - { - $this->config = $config; - } - - /** - * @param mixed $offset - * @return null - */ - public function offsetUnset($offset) - { - unset($this->notifications[$offset]); - } -} diff --git a/src/Notifynder/Categories/CategoryManager.php b/src/Notifynder/Categories/CategoryManager.php deleted file mode 100755 index aca475f..0000000 --- a/src/Notifynder/Categories/CategoryManager.php +++ /dev/null @@ -1,133 +0,0 @@ -categoryRepo = $categoryRepo; - } - - /** - * Find a category by name. - * - * @param $name - * @throws CategoryNotFoundException - * @return mixed - */ - public function findByName($name) - { - $category = $this->categoryRepo->findByName($name); - - if (is_null($category)) { - $error = 'Category Not Found'; - throw new CategoryNotFoundException($error); - } - - return $category; - } - - /** - * Find categories by names, - * pass the name as an array. - * - * @param $name - * @throws CategoryNotFoundException - * @return mixed - */ - public function findByNames(array $name) - { - $category = $this->categoryRepo->findByNames($name); - - if (count($category) == 0) { - $error = 'Category Not Found'; - throw new CategoryNotFoundException($error); - } - - return $category; - } - - /** - * Find a category by id. - * - * @param $categoryId - * @throws CategoryNotFoundException - * @return mixed - */ - public function find($categoryId) - { - $category = $this->categoryRepo->find($categoryId); - - if (is_null($category)) { - $error = 'Category Not Found'; - throw new CategoryNotFoundException($error); - } - - return $category; - } - - /** - * Add a category to the DB. - * - * @param array $name - * @param $text - * @return \Fenos\Notifynder\Models\NotificationCategory - */ - public function add($name, $text) - { - return $this->categoryRepo->add($name, $text); - } - - /** - * Delete category by ID. - * - * @param $categoryId - * @return mixed - */ - public function delete($categoryId) - { - return $this->categoryRepo->delete($categoryId); - } - - /** - * Delete category by name. - * - * @param $name - * @return mixed - */ - public function deleteByName($name) - { - return $this->categoryRepo->deleteByName($name); - } - - /** - * Update a category. - * - * @param array $data - * @param $categoryId - * @return mixed - */ - public function update(array $data, $categoryId) - { - return $this->categoryRepo->update($data, $categoryId); - } -} diff --git a/src/Notifynder/Categories/CategoryRepository.php b/src/Notifynder/Categories/CategoryRepository.php deleted file mode 100755 index d0c5e4f..0000000 --- a/src/Notifynder/Categories/CategoryRepository.php +++ /dev/null @@ -1,114 +0,0 @@ -categoryModel = $categoryModel; - } - - /** - * Find By Id. - * - * @param $categoryId - * @return mixed - */ - public function find($categoryId) - { - return $this->categoryModel->find($categoryId); - } - - /** - * Find by name. - * - * @param $name - * @return mixed - */ - public function findByName($name) - { - return $this->categoryModel->where('name', $name) - ->first(); - } - - /** - * Find by names returning - * lists of ids. - * - * @param $name - * @return mixed - */ - public function findByNames(array $name) - { - return $this->categoryModel->whereIn('name', $name) - ->get(); - } - - /** - * Add a category to the DB. - * - * @param array $name - * @param $text - * @return static - */ - public function add($name, $text) - { - return $this->categoryModel->create(compact('name', 'text')); - } - - /** - * Delete category by ID. - * - * @param $categoryId - * @return mixed - */ - public function delete($categoryId) - { - return $this->categoryModel->where('id', $categoryId) - ->delete(); - } - - /** - * Delete category by name. - * - * @param $name - * @return mixed - */ - public function deleteByName($name) - { - return $this->categoryModel->where('name', $name) - ->delete(); - } - - /** - * Update a category by id. - * - * @param array $data - * @param $categoryId - * @return mixed - */ - public function update(array $data, $categoryId) - { - return $this->categoryModel->where('id', $categoryId) - ->update($data); - } -} diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php new file mode 100644 index 0000000..a8f9308 --- /dev/null +++ b/src/Notifynder/Collections/Config.php @@ -0,0 +1,70 @@ +items = app('config')->get('notifynder'); + } + + public function isPolymorphic() + { + return (bool) $this->get('polymorphic'); + } + + public function getNotificationModel() + { + $class = $this->get('notification_model'); + if(class_exists($class)) { + return $class; + } + return Notification::class; + } + + public function getNotifiedModel() + { + $class = $this->get('model'); + if(class_exists($class)) { + return $class; + } + throw new \InvalidArgumentException("The model class [{$class}] doesn't exist."); + } + + public function getAdditionalFields() + { + return Arr::flatten($this->get('additional_fields', [])); + } + + public function get($key, $default = null) + { + return Arr::get($this->items, $key, $default); + } + + public function has($key) + { + return Arr::has($this->items, $key); + } + + public function set($key, $value = null) + { + Arr::set($this->items, $key, $value); + } + + public function __get($key) + { + return $this->get($key); + } + + public function __set($key, $value) + { + $this->set($key, $value); + } +} \ No newline at end of file diff --git a/src/Notifynder/Contracts/CategoryDB.php b/src/Notifynder/Contracts/CategoryDB.php deleted file mode 100755 index 34d107c..0000000 --- a/src/Notifynder/Contracts/CategoryDB.php +++ /dev/null @@ -1,71 +0,0 @@ - [ - * 'name.category' => 'text to translate' - * ] - * ] - */ -interface NotifynderTranslator -{ - /** - * Translate the given category. - * - * @param $language - * @param $nameCategory - * @return mixed - * @throws NotificationLanguageNotFoundException - * @throws NotificationTranslationNotFoundException - */ - public function translate($language, $nameCategory); - - /** - * Get selected language of translations. - * - * @param $language - * @return mixed - * @throws NotificationLanguageNotFoundException - */ - public function getLanguage($language); - - /** - * Get translations. - * - * @return array|mixed - */ - public function getTranslations(); -} diff --git a/src/Notifynder/Contracts/Sender.php b/src/Notifynder/Contracts/Sender.php deleted file mode 100755 index 9596e1e..0000000 --- a/src/Notifynder/Contracts/Sender.php +++ /dev/null @@ -1,17 +0,0 @@ -notificationCategory = $notificationCategory; - $this->notificationGroup = $notificationGroup; - } - - /** - * Add a category in a group. - * - * @param $groupId - * @param $categoryId - * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static - */ - public function addCategoryToGroupById($groupId, $categoryId) - { - $group = $this->notificationGroup->find($groupId); - $group->categories()->attach($categoryId); - - return $group; - } - - /** - * Add a category in a group - * by names given. - * - * @param $groupName - * @param $categoryName - * @return mixed - */ - public function addCategoryToGroupByName($groupName, $categoryName) - { - $group = $this->notificationGroup->where('name', $groupName)->first(); - - $category = $this->notificationCategory->findByName($categoryName); - - $group->categories()->attach($category->id); - - return $group; - } - - /** - * Add multiple categories by them names - * to a group. - * - * @param $groupName - * @param $names - * @return mixed - */ - public function addMultipleCategoriesToGroup($groupName, array $names) - { - $group = $this->notificationGroup->where('name', $groupName)->first(); - - $categories = $this->notificationCategory->findByNames($names); - - foreach ($categories as $category) { - $group->categories()->attach($category->id); - } - - return $group; - } -} diff --git a/src/Notifynder/Groups/GroupManager.php b/src/Notifynder/Groups/GroupManager.php deleted file mode 100755 index c7bebd8..0000000 --- a/src/Notifynder/Groups/GroupManager.php +++ /dev/null @@ -1,147 +0,0 @@ -groupRepo = $groupRepo; - $this->groupCategory = $groupCategory; - } - - /** - * Find a group by id. - * - * @param $groupId - * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static - * @throws \Fenos\Notifynder\Exceptions\NotifynderGroupNotFoundException - */ - public function findById($groupId) - { - $group = $this->groupRepo->find($groupId); - - if (is_null($group)) { - $error = 'Group Not Found'; - throw new NotifynderGroupNotFoundException($error); - } - - return $group; - } - - /** - * Find a group By name. - * - * @param $groupName - * @return mixed - * @throws \Fenos\Notifynder\Exceptions\NotifynderGroupNotFoundException - */ - public function findByName($groupName) - { - $group = $this->groupRepo->findByName($groupName); - - if (is_null($group)) { - $error = 'Group Not Found'; - throw new NotifynderGroupNotFoundException($error); - } - - return $group; - } - - /** - * Add category to a group - * giving the ids of them. - * - * @param $groupId - * @param $categoryId - * @return mixed - */ - public function addCategoryToGroupById($groupId, $categoryId) - { - return $this->groupCategory->addCategoryToGroupById($groupId, $categoryId); - } - - /** - * Add category to a group - * giving the ids of them. - * - * @param $groupName - * @param $categoryName - * @return mixed - */ - public function addCategoryToGroupByName($groupName, $categoryName) - { - return $this->groupCategory->addCategoryToGroupByName($groupName, $categoryName); - } - - /** - * Add Multiple categories in a group - * First parameter is the group name - * all the rest are categories. - * - * @return mixed - */ - public function addMultipleCategoriesToGroup() - { - $args = func_get_args(); - - // First parameter is the group name - $groupName = array_shift($args); - - $names = (is_array($args[0])) ? $args[0] : $args; - - return $this->groupCategory->addMultipleCategoriesToGroup($groupName, $names); - } - - /** - * Add a group in the db. - * - * @param $name - * @throws InvalidArgumentException - * @return \Illuminate\Database\Eloquent\Model|static - */ - public function addGroup($name) - { - if ($this->isStringWithDots($name)) { - return $this->groupRepo->create($name); - } - - $error = 'The name must be a string with dots as namespaces'; - throw new InvalidArgumentException($error); - } - - /** - * Check if a string with dots. - * - * @param $name - * @return bool - */ - protected function isStringWithDots($name) - { - return strpos($name, '.'); - } -} diff --git a/src/Notifynder/Groups/GroupRepository.php b/src/Notifynder/Groups/GroupRepository.php deleted file mode 100755 index 8419c76..0000000 --- a/src/Notifynder/Groups/GroupRepository.php +++ /dev/null @@ -1,70 +0,0 @@ -groupModel = $groupModel; - } - - /** - * Find a group by ID. - * - * @param $groupId - * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static - */ - public function find($groupId) - { - return $this->groupModel->find($groupId); - } - - /** - * Find a group by name. - * - * @param $name - * @return mixed - */ - public function findByName($name) - { - return $this->groupModel->where('name', $name)->first(); - } - - /** - * Create a new group. - * - * @param $name - * @return \Illuminate\Database\Eloquent\Model - */ - public function create($name) - { - return $this->groupModel->create(compact('name')); - } - - /** - * Delete a group. - * - * @param $groupId - * @return mixed - */ - public function delete($groupId) - { - return $this->groupModel->where('id', $groupId)->delete(); - } -} diff --git a/src/Notifynder/Handler/Dispatcher.php b/src/Notifynder/Handler/Dispatcher.php deleted file mode 100755 index e346206..0000000 --- a/src/Notifynder/Handler/Dispatcher.php +++ /dev/null @@ -1,149 +0,0 @@ -event = $event; - } - - /** - * It fire the event associated to the passed key, - * trigger the listener method bound with. - * - * @param Notifynder $notifynder - * @param string $eventName - * @param string $categoryName - * @param mixed|null $values - * @return mixed|null - */ - public function fire(Notifynder $notifynder, $eventName, $categoryName = null, $values = []) - { - // Generate the event from the name given - $eventName = $this->generateEventName($eventName); - - // Instantiate the Notifynder event Object that will provide - // nice way to get your data on the handler. It will be the first - // parameter - $event = new NotifynderEvent($eventName, $categoryName, $values); - - // Fire the event given expecting an array of notifications or false - // value to not send the notification - $notificationsResult = $this->event->fire($eventName, [$event, $notifynder]); - - // if the event return an array of notifications then it will - // send automatically - if ($this->hasNotificationToSend($notificationsResult)) { - - // Send the notification with the sender - // method specified in the property - return call_user_func_array( - [$notifynder, $this->sender], - [$notificationsResult[0]] - ); - } - } - - /** - * Delegate events to categories. - * - * @param Notifynder $notifynder - * @param array $data - * @param array $events - * @return mixed - */ - public function delegate(Notifynder $notifynder, $data, array $events) - { - foreach ($events as $category => $event) { - $this->fire($notifynder, $event, $category, $data); - } - } - - /** - * Tell the dispatcher to send - * the notification with a custom - * (extended method). - * - * @param $customMethod - * @return $this - */ - public function sendWith($customMethod) - { - $this->sender = $customMethod; - - return $this; - } - - /** - * Boot The listeners. - * - * @param array $listeners - */ - public function boot(array $listeners) - { - if (count($listeners) > 0) { - foreach ($listeners as $key => $listener) { - // Notifynder.name.* - $event = $this->generateEventName($key); - $this->event->listen($event, $listener); - } - } - } - - /** - * Check if the fired method has some notifications - * to send. - * - * @param $notificationsResult - * @return bool - */ - public function hasNotificationToSend($notificationsResult) - { - return is_array($notificationsResult) - and count($notificationsResult) > 0 - and $notificationsResult[0] !== false - and count($notificationsResult[0]) > 0; - } - - /** - * Get Event name. - * - * @param $eventName - * @return string - */ - protected function generateEventName($eventName) - { - return static::$defaultWildcard.'.'.str_replace('@', '.', $eventName); - } -} diff --git a/src/Notifynder/Handler/NotifynderEvent.php b/src/Notifynder/Handler/NotifynderEvent.php deleted file mode 100755 index 8904301..0000000 --- a/src/Notifynder/Handler/NotifynderEvent.php +++ /dev/null @@ -1,85 +0,0 @@ -event = $event; - $this->values = $values; - $this->category = $category; - } - - /** - * @return mixed - */ - public function getEvent() - { - return $this->event; - } - - /** - * Get a value from the given - * values. - * - * @param $name - * @return mixed - */ - public function get($name) - { - if (array_key_exists($name, $this->values)) { - return $this->values[$name]; - } - } - - /** - * @return string - */ - public function getCategory() - { - return $this->category; - } - - /** - * @param $name - * @return mixed - */ - public function __get($name) - { - return $this->get($name); - } - - /** - * @return NotifynderEvent - */ - public function getNotifynderEvent() - { - return $this; - } -} diff --git a/src/Notifynder/Handler/NotifynderHandler.php b/src/Notifynder/Handler/NotifynderHandler.php deleted file mode 100755 index 9d5fa21..0000000 --- a/src/Notifynder/Handler/NotifynderHandler.php +++ /dev/null @@ -1,121 +0,0 @@ -getNotifynderEvent(); - - $eventName = $this->getEventName($event->getEvent()); - - if ($this->listenerIsRegistered($eventName)) { - - // Make sure a notifynder instance is passed to the event - // invoker method - $notifynder = (is_null($notifynder)) ? $this->getNotifynder() : $notifynder; - - // Build the notifications - $builtNotifications = call_user_func_array([$this, $eventName], [$event, $notifynder]); - - // If the listener is the NotifynderEvent that means - // we are triggering this from the Notifynder::fire() - // Event, it will take care of sending the notification - if ($eventListener instanceof NotifynderEvent) { - return $builtNotifications; - } - - // Event has been dispatched manually from the native - // Laravel eventing system then I'll send the notification - // Right here - if ($this->hasNotificationToSend([$builtNotifications])) { - return $notifynder->send($builtNotifications); - } - } - } - - /** - * Check if the listener exists on the class - * adding when as convention. - * - * ['postAdd'] whenPostAdd] - * - * @param $eventName - * @return bool - */ - protected function listenerIsRegistered($eventName) - { - return method_exists($this, $eventName); - } - - /** - * Get Event Name from the key - * it use a convention. - * - * given user.post.add -> postAdd - * given user@postAdd -> postAdd - * - * @param $event - * @return string - */ - protected function getEventName($event) - { - // Remove the Notifynder namespaces for - // the find the method - $event = str_replace(Dispatcher::$defaultWildcard.'.', '', $event); - - $eventNameSpace = (strpos($event, '@')) - ? explode('@', $event) - : explode('.', $event); - - // Check if the name has been splitted in 2 - if (count($eventNameSpace) > 1) { - array_shift($eventNameSpace); - } - - $nameMethod = implode('_', $eventNameSpace); - - return camel_case($nameMethod); - } - - /** - * Get Notifynder Instance. - * - * @return Notifynder - */ - protected function getNotifynder() - { - $notifynder = app('notifynder'); - - return $notifynder; - } - - /** - * Check if the fired method has some notifications - * to send. - * - * @param $notificationsResult - * @return bool - */ - protected function hasNotificationToSend($notificationsResult) - { - return is_array($notificationsResult) - and count($notificationsResult) > 0 - and $notificationsResult[0] !== false - and count($notificationsResult[0]) > 0; - } -} diff --git a/src/Notifynder/Helpers/helpers.php b/src/Notifynder/Helpers/helpers.php new file mode 100644 index 0000000..a459d65 --- /dev/null +++ b/src/Notifynder/Helpers/helpers.php @@ -0,0 +1,18 @@ +get($key, $default); + } +} \ No newline at end of file diff --git a/src/Notifynder/Managers/NotifynderManager.php b/src/Notifynder/Managers/NotifynderManager.php new file mode 100755 index 0000000..549ec21 --- /dev/null +++ b/src/Notifynder/Managers/NotifynderManager.php @@ -0,0 +1,19 @@ +mergeFillable(); - $this->fillable($fillables); + $this->fillable($this->mergeFillables()); parent::__construct($attributes); } - /** - * Custom Collection. - * - * @param array $models - * @return NotifynderCollection|\Illuminate\Database\Eloquent\Collection - */ - public function newCollection(array $models = []) - { - return new NotifynderCollection($models); - } - - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function body() + public function category() { return $this->belongsTo(NotificationCategory::class, 'category_id'); } - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo - */ public function from() { - // check if on the configurations file there is the option - // polymorphic set to true, if so Notifynder will work - // polymorphic. - if (config('notifynder.polymorphic') == false) { - return $this->belongsTo(config('notifynder.model'), 'from_id'); + if (notifynder_config()->isPolymorphic()) { + return $this->belongsTo(notifynder_config()->getModel(), 'from_id'); } - return $this->morphTo(); } - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo - */ public function to() { - // check if on the configurations file there is the option - // polymorphic set to true, if so Notifynder will work - // polymorphic. - if (config('notifynder.polymorphic') == false) { - return $this->belongsTo(config('notifynder.model'), 'to_id'); + if (notifynder_config()->isPolymorphic()) { + return $this->belongsTo(notifynder_config()->getModel(), 'to_id'); } - return $this->morphTo(); } - /** - * Not read scope. - * - * @param $query - * @return mixed - */ - public function scopeWithNotRead($query) - { - return $query->where('read', 0); - } - - /** - * Only Expired Notification scope. - * - * @param $query - * @return mixed - */ - public function scopeOnlyExpired($query) - { - return $query->where('expire_time', '<', Carbon::now()); - } - - /** - * Where Polymorphic. - * - * @param $query - * @param $toId - * @param $type - * @return mixed - */ - public function scopeWherePolymorphic($query, $toId, $type) - { - if (! $type or config('notifynder.polymorphic') === false) { - return $query->where('to_id', $toId); - } - - return $query->where('to_id', $toId) - ->where('to_type', $type); - } - - /** - * Get parsed body attributes. - * - * @return string - */ - public function getNotifyBodyAttribute() - { - $notifynderParse = new NotifynderParser(); - - return $notifynderParse->parse($this); - } - - /** - * Get parsed body attributes. - * - * @return string - */ - public function getTextAttribute() - { - return $this->notify_body; - } - - /** - * @param $value - * @return \Fenos\Notifynder\Notifications\ExtraParams - */ - public function getExtraAttribute($value) - { - if (! empty($value)) { - return new ExtraParams($value); - } - - return new ExtraParams([]); - } - - /** - * Filter Scope by category. - * - * @param $query - * @param $category - * @return mixed - */ - public function scopeByCategory($query, $category) - { - if (is_numeric($category)) { - return $query->where('category_id', $category); - } - - return $query->whereHas('body', function ($categoryQuery) use ($category) { - $categoryQuery->where('name', $category); - }); - } - - /** - * Get custom required fields from the configs - * so that we can automatically bind them to the model - * fillable property. - * - * @return mixed - */ public function getCustomFillableFields() { - if (function_exists('app') && app() instanceof Container) { - return Arr::flatten(config('notifynder.additional_fields', [])); - } - - return []; + return notifynder_config()->getAdditionalFields(); } - /** - * @return array - */ - protected function mergeFillable() + protected function mergeFillables() { $fillables = array_unique($this->getFillable() + $this->getCustomFillableFields()); return $fillables; } - - /** - * Filter Scope by stack. - * - * @param $query - * @param $stackId - * @return mixed - */ - public function scopeByStack($query, $stackId) - { - return $query->where('stack_id', $stackId); - } - - /** - * Check if this notification is part of a stack. - * - * @return bool - */ - public function hasStack() - { - return ! is_null($this->stack_id); - } - - /** - * Get the full stack of notifications if this has one. - * - * @return null|Collection - */ - public function getStack() - { - if ($this->hasStack()) { - return static::byStack($this->stack_id)->get(); - } - } } diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 55569e1..1d37ab0 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -4,49 +4,25 @@ use Illuminate\Database\Eloquent\Model; -/** - * Class NotificationCategory. - * - * @property int id - * @property string name - * @property string text - */ class NotificationCategory extends Model { - /** - * @var string - */ protected $table = 'notification_categories'; - /** - * @var array - */ protected $fillable = ['name', 'text']; - /** - * @var bool - */ public $timestamps = false; - /** - * Relation with the notifications. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ public function notifications() { - return $this->hasMany('Fenos\Notifynder\Models\Notification', 'category_id'); + $config = app('notifynder.config'); + $model = $config->getNotificationModel(); + return $this->hasMany($model, 'category_id'); } - /** - * Groups Categories. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ public function categories() { return $this->belongsToMany( - 'Fenos\Notifynder\Models\NotificationGroup', + NotificationGroup::class, 'notifications_categories_in_groups', 'category_id', 'group_id' diff --git a/src/Notifynder/Models/NotificationGroup.php b/src/Notifynder/Models/NotificationGroup.php index bb0add1..9abccfc 100755 --- a/src/Notifynder/Models/NotificationGroup.php +++ b/src/Notifynder/Models/NotificationGroup.php @@ -4,28 +4,16 @@ use Illuminate\Database\Eloquent\Model; -/** - * Class NotificationGroup. - */ class NotificationGroup extends Model { - /** - * @var array - */ protected $fillable = ['name']; - /** - * @var bool - */ public $timestamps = false; - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ public function categories() { return $this->belongsToMany( - 'Fenos\Notifynder\Models\NotificationCategory', + NotificationCategory::class, 'notifications_categories_in_groups', 'group_id', 'category_id' ); diff --git a/src/Notifynder/Models/NotifynderCollection.php b/src/Notifynder/Models/NotifynderCollection.php deleted file mode 100755 index 6a5ea53..0000000 --- a/src/Notifynder/Models/NotifynderCollection.php +++ /dev/null @@ -1,80 +0,0 @@ -items as $key => $item) { - try { - $translation = $this->translator() - ->translate($language, $this->items[$key]['body']['name']); - - $this->items[$key]['body']['text'] = $translation; - } catch (NotificationTranslationNotFoundException $e) { - $this->items[$key]['body']['text']; - } - } - - $this->parse(); - - return $this; - } - - /** - * Parse the body of the notification. - * - * @return $this - */ - public function parse() - { - $parser = new NotifynderParser(); - - foreach ($this->items as $key => $item) { - $this->items[$key]['notify_body'] = $parser->parse($item); - $this->items[$key]['text'] = $this->items[$key]['notify_body']; - } - - return $this; - } -} diff --git a/src/Notifynder/Notifable.php b/src/Notifynder/Notifable.php deleted file mode 100755 index 7ae4dd1..0000000 --- a/src/Notifynder/Notifable.php +++ /dev/null @@ -1,151 +0,0 @@ -morphMany(config('notifynder.notification_model'), 'to'); - } else { - return $this->hasMany(config('notifynder.notification_model'), 'to_id'); - } - } - - /** - * Read all Notifications. - * - * @return mixed - */ - public function readAllNotifications() - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->readAll($this->id); - } - - /** - * Read Limiting Notifications. - * - * @param int $numbers - * @param string $order - * @return mixed - */ - public function readLimitNotifications($numbers = 10, $order = 'ASC') - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->readLimit($this->id, $numbers, $order); - } - - /** - * Delete Limiting Notifications. - * - * @param int $numbers - * @param string $order - * @return mixed - */ - public function deleteLimitNotifications($numbers = 10, $order = 'ASC') - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->deleteLimit($this->id, $numbers, $order); - } - - /** - * Delete all Notifications. - * - * @return bool - */ - public function deleteAllNotifications() - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->deleteAll($this->id); - } - - /** - * Get Not Read. - * - * @param null $limit - * @param int|null $paginate - * @param string $order - * @param Closure $filterScope - * @return mixed - */ - public function getNotificationsNotRead($limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->getNotRead($this->id, $limit, $paginate, $order, $filterScope); - } - - /** - * Get all notifications. - * - * @param null $limit - * @param int|null $paginate - * @param string $order - * @param Closure $filterScope - * @return mixed - */ - public function getNotifications($limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->getAll($this->id, $limit, $paginate, $order, $filterScope); - } - - /** - * Get last notification. - * - * @param null $category - * @param Closure $filterScope - * @return mixed - */ - public function getLastNotification($category = null, Closure $filterScope = null) - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->getLastNotification($this->id, $category, $filterScope); - } - - /** - * Count Not read notification. - * - * @param Closure $filterScope - * @return mixed - */ - public function countNotificationsNotRead(Closure $filterScope = null) - { - return $this->notifynderInstance()->entity( - $this->getMorphClass() - )->countNotRead($this->id, $filterScope); - } - - /** - * @return \Fenos\Notifynder\NotifynderManager - */ - protected function notifynderInstance() - { - return app('notifynder'); - } -} diff --git a/src/Notifynder/Notifications/ExtraParams.php b/src/Notifynder/Notifications/ExtraParams.php deleted file mode 100644 index 38b16f4..0000000 --- a/src/Notifynder/Notifications/ExtraParams.php +++ /dev/null @@ -1,168 +0,0 @@ -isJson($extraParams)) { - $this->extraParams = json_decode($extraParams, true); - } else { - $this->extraParams = (array) $extraParams; - } - } - - /** - * Convert the model instance to JSON. - * - * @param int $options - * @return string - */ - public function toJson($options = 0) - { - return json_encode($this->jsonSerialize(), $options); - } - - /** - * Convert the object into something JSON serializable. - * - * @return array - */ - public function jsonSerialize() - { - return $this->toArray(); - } - - /** - * @return array - */ - public function toArray() - { - // Already possible json - if ($this->isJson($this->extraParams)) { - return json_decode($this->extraParams, true); - } - - return $this->extraParams; - } - - /** - * The __toString method allows a class to decide how it will react when it is converted to a string. - * - * @return string - */ - public function __toString() - { - $extraParams = $this->extraParams; - - if (is_array($extraParams) || $extraParams instanceof stdClass) { - return $this->toJson(); - } - - return $extraParams; - } - - /** - * Check if the extra param - * exists. - * - * @param $name - * @return bool - */ - public function has($name) - { - $arr = $this->extraParams; - - return isset($arr[$name]); - } - - /** - * is utilized for reading data from inaccessible members. - * - * @param $name string - * @return mixed - */ - public function __get($name) - { - $params = $this->toArray(); - - if (array_key_exists($name, $params)) { - return $params[$name]; - } - } - - /** - * Whether a offset exists. - * - * @param mixed $offset - * @return bool - */ - public function offsetExists($offset) - { - return $this->has($offset); - } - - /** - * @param mixed $offset - * @return mixed Can return all value types. - */ - public function offsetGet($offset) - { - return $this->extraParams[$offset]; - } - - /** - * @param mixed $offset - * @param mixed $value - */ - public function offsetSet($offset, $value) - { - $this->extraParams[$offset] = $value; - } - - /** - * @param mixed $offset - */ - public function offsetUnset($offset) - { - unset($this->extraParams[$offset]); - } - - /** - * Check if the value - * is a json string. - * - * @param $value - * @return bool - */ - public function isJson($value) - { - if (! is_string($value)) { - return false; - } - - json_decode($value); - - return json_last_error() == JSON_ERROR_NONE; - } -} diff --git a/src/Notifynder/Notifications/NotificationManager.php b/src/Notifynder/Notifications/NotificationManager.php deleted file mode 100755 index 44a9f87..0000000 --- a/src/Notifynder/Notifications/NotificationManager.php +++ /dev/null @@ -1,278 +0,0 @@ -notifynderRepo = $notifynderRepo; - } - - /** - * Set the entity for polymorphic. - * - * @param $name - * @return $this - */ - public function entity($name) - { - $this->entity = $name; - - return $this; - } - - /** - * Find a notification by ID. - * - * @param $notificationId - * @return NotificationModel|\Illuminate\Database\Eloquent\Model|static - * @throws \Fenos\Notifynder\Exceptions\NotificationNotFoundException - */ - public function find($notificationId) - { - $notification = $this->notifynderRepo->find($notificationId); - - if (is_null($notification)) { - $error = 'Notification Not found'; - throw new NotificationNotFoundException($error); - } - - return $notification; - } - - /** - * Make read one notification giving - * the ID of it. - * - * @param $notificationId - * @return bool|\Fenos\Notifynder\Models\Notification - */ - public function readOne($notificationId) - { - $notification = $this->find($notificationId); - - return $this->notifynderRepo->readOne($notification); - } - - /** - * Read notifications in base the number - * Given. - * - * @param $toId - * @param $numbers - * @param string $order - * @return mixed - */ - public function readLimit($toId, $numbers, $order = 'ASC') - { - return $this->notifynderRepo->readLimit($toId, $this->entity, $numbers, $order); - } - - /** - * Read all notification of the - * given entity. - * - * @param $toId - * @return Number - */ - public function readAll($toId) - { - return $this->notifynderRepo->readAll($toId, $this->entity); - } - - /** - * Delete a notification giving the id - * of it. - * - * @param $notificationId - * @return bool - */ - public function delete($notificationId) - { - return $this->notifynderRepo->delete($notificationId); - } - - /** - * Delete numbers of notifications equals - * to the number passing as 2 parameter of - * the current user. - * - * @param $entityId - * @param $number - * @param $order - * @return mixed - */ - public function deleteLimit($entityId, $number, $order = 'asc') - { - return $this->notifynderRepo->deleteLimit($entityId, $this->entity, $number, $order); - } - - /** - * Delete all notification of a given - * Entity. - * - * @param $entityId - * @return bool - */ - public function deleteAll($entityId) - { - return $this->notifynderRepo->deleteAll($entityId, $this->entity); - } - - /** - * Delete All notifications from a - * defined category. - * - * @param $categoryName string - * @param $expired Bool - * @return bool - */ - public function deleteByCategory($categoryName, $expired = false) - { - return $this->notifynderRepo->deleteByCategory($categoryName, $expired); - } - - /** - * Get notifications not read - * of the entity given. - * - * @param $toId - * @param $limit - * @param int|null $paginate - * @param string $orderDate - * @param Closure $filterScope - * @return mixed - */ - public function getNotRead($toId, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) - { - $notifications = $this->notifynderRepo->getNotRead( - $toId, $this->entity, - $limit, $paginate, $orderDate, - $filterScope - ); - - if (is_int(intval($paginate)) && $paginate) { - return new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ - 'path' => LengthAwarePaginator::resolveCurrentPath(), - ]); - } - - return $notifications->parse(); - } - - /** - * Get All notifications. - * - * @param $toId - * @param $limit - * @param int|null $paginate - * @param string $orderDate - * @param Closure $filterScope - * @return mixed - */ - public function getAll($toId, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) - { - $notifications = $this->notifynderRepo->getAll( - $toId, $this->entity, - $limit, $paginate, $orderDate, - $filterScope - ); - - if (is_int(intval($paginate)) && $paginate) { - return new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [ - 'path' => LengthAwarePaginator::resolveCurrentPath(), - ]); - } - - return $notifications->parse(); - } - - /** - * Get last notification of the - * given entity. - * - * @param $toId - * @param Closure $filterScope - * @return mixed - */ - public function getLastNotification($toId, Closure $filterScope = null) - { - return $this->notifynderRepo->getLastNotification($toId, $this->entity, $filterScope); - } - - /** - * Get last notification of the - * given entity of the specific category. - * - * @param $category - * @param $toId - * @param Closure $filterScope - * @return mixed - */ - public function getLastNotificationByCategory($category, $toId, Closure $filterScope = null) - { - return $this->notifynderRepo->getLastNotificationByCategory($category, $toId, $this->entity, $filterScope); - } - - /** - * Send single notification. - * - * @param array $info - * @return static - */ - public function sendOne(array $info) - { - return $this->notifynderRepo->storeSingle($info); - } - - /** - * Send multiple notifications. - * - * @param array $info - * @return mixed - */ - public function sendMultiple(array $info) - { - return $this->notifynderRepo->storeMultiple($info); - } - - /** - * Get number of notification - * not read. - * - * @param $toId - * @param Closure $filterScope - * @return mixed - */ - public function countNotRead($toId, Closure $filterScope = null) - { - return $this->notifynderRepo->countNotRead($toId, $this->entity, $filterScope); - } -} diff --git a/src/Notifynder/Notifications/NotificationRepository.php b/src/Notifynder/Notifications/NotificationRepository.php deleted file mode 100755 index 1b7e4de..0000000 --- a/src/Notifynder/Notifications/NotificationRepository.php +++ /dev/null @@ -1,416 +0,0 @@ -notification = $notification; - $this->db = $db; - } - - /** - * Find notification by id. - * - * @param $notificationId - * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static - */ - public function find($notificationId) - { - return $this->notification->find($notificationId); - } - - /** - * Save a single notification sent. - * - * @param array $info - * @return Notification - */ - public function storeSingle(array $info) - { - return $this->notification->create($info); - } - - /** - * Save multiple notifications sent - * at once. - * - * @param array $notifications - * @return mixed - */ - public function storeMultiple(array $notifications) - { - $this->db->beginTransaction(); - $stackId = $this->db->table( - $this->notification->getTable() - )->max('stack_id') + 1; - foreach ($notifications as $key => $notification) { - $notifications[$key]['stack_id'] = $stackId; - } - $insert = $this->db->table( - $this->notification->getTable() - )->insert($notifications); - $this->db->commit(); - - return $insert; - } - - /** - * Make Read One Notification. - * - * @param Notification $notification - * @return bool|Notification - */ - public function readOne(Notification $notification) - { - $notification->read = 1; - - if ($notification->save()) { - return $notification; - } - - return false; - } - - /** - * Read notifications in base the number - * Given. - * - * @param $toId - * @param $entity - * @param $numbers - * @param $order - * @return int - */ - public function readLimit($toId, $entity, $numbers, $order) - { - $notifications = $this->notification->withNotRead() - ->wherePolymorphic($toId, $entity) - ->limit($numbers) - ->orderBy('id', $order) - ->lists('id'); - - return $this->notification->whereIn('id', $notifications) - ->update(['read' => 1]); - } - - /** - * Make read all notification not read. - * - * @param $toId - * @param $entity - * @return int - */ - public function readAll($toId, $entity) - { - return $this->notification->withNotRead() - ->wherePolymorphic($toId, $entity) - ->update(['read' => 1]); - } - - /** - * Delete a notification giving the id - * of it. - * - * @param $notificationId - * @return bool - */ - public function delete($notificationId) - { - return $this->notification->where('id', $notificationId)->delete(); - } - - /** - * Delete All notifications about the - * current user. - * - * @param $toId int - * @param $entity - * @return bool - */ - public function deleteAll($toId, $entity) - { - $query = $this->db->table( - $this->notification->getTable() - ); - - return $this->notification->scopeWherePolymorphic($query, $toId, $entity) - ->delete(); - } - - /** - * Delete All notifications from a - * defined category. - * - * @param $categoryName int - * @param $expired Bool - * @return bool - */ - public function deleteByCategory($categoryName, $expired = false) - { - $query = $this->notification->whereHas( - 'body', - function ($query) use ($categoryName) { - $query->where('name', $categoryName); - } - ); - - if ($expired == true) { - return $query->onlyExpired()->delete(); - } - - return $query->delete(); - } - - /** - * Delete numbers of notifications equals - * to the number passing as 2 parameter of - * the current user. - * - * @param $userId int - * @param $entity - * @param $number int - * @param $order string - * @return int - * @throws \Exception - */ - public function deleteLimit($userId, $entity, $number, $order) - { - $notificationsIds = $this->notification - ->wherePolymorphic($userId, $entity) - ->orderBy('id', $order) - ->select('id') - ->limit($number) - ->lists('id'); - - if (count($notificationsIds) == 0) { - return false; - } - - return $this->notification->whereIn('id', $notificationsIds) - ->delete(); - } - - /** - * Retrieve notifications not Read - * You can also limit the number of - * Notification if you don't it will get all. - * - * @param $toId - * @param $entity - * @param int|null $limit - * @param int|null $paginate - * @param string $orderDate - * @param Closure|null $filterScope - * @return mixed - */ - public function getNotRead( - $toId, - $entity, - $limit = null, - $paginate = null, - $orderDate = 'desc', - Closure $filterScope = null - ) { - $query = $this->notification->with('body', 'from') - ->wherePolymorphic($toId, $entity) - ->withNotRead() - ->orderBy('read', 'ASC') - ->orderBy('created_at', $orderDate); - - if ($limit && ! $paginate) { - $query->limit($limit); - } - - $query = $this->applyFilter($filterScope, $query); - - if (is_int(intval($paginate)) && $paginate) { - return $query->paginate($limit); - } - - return $query->get(); - } - - /** - * Retrieve all notifications, not read - * in first. - * You can also limit the number of - * Notifications if you don't, it will get all. - * - * @param $toId - * @param $entity - * @param null $limit - * @param int|null $paginate - * @param string $orderDate - * @param Closure $filterScope - * @return mixed - */ - public function getAll( - $toId, - $entity, - $limit = null, - $paginate = null, - $orderDate = 'desc', - Closure $filterScope = null - ) { - $query = $this->notification->with('body', 'from') - ->wherePolymorphic($toId, $entity) - ->orderBy('read', 'ASC') - ->orderBy('created_at', $orderDate); - - if ($limit && ! $paginate) { - $query->limit($limit); - } - - $query = $this->applyFilter($filterScope, $query); - - if (is_int(intval($paginate)) && $paginate) { - return $query->paginate($limit); - } - - return $query->get(); - } - - /** - * get number Notifications - * not read. - * - * @param $toId - * @param $entity - * @param Closure $filterScope - * @return mixed - */ - public function countNotRead($toId, $entity, Closure $filterScope = null) - { - $query = $this->notification->wherePolymorphic($toId, $entity) - ->withNotRead() - ->select($this->db->raw('Count(*) as notRead')); - - $query = $this->applyFilter($filterScope, $query); - - return $query->count(); - } - - /** - * Get last notification of the current - * entity. - * - * @param $toId - * @param $entity - * @param Closure $filterScope - * @return mixed - */ - public function getLastNotification($toId, $entity, Closure $filterScope = null) - { - $query = $this->notification->wherePolymorphic($toId, $entity) - ->orderBy('created_at', 'DESC'); - - $query = $this->applyFilter($filterScope, $query); - - return $query->first(); - } - - /** - * Get last notification of the current - * entity of a specific category. - * - * @param $category - * @param $toId - * @param $entity - * @param Closure $filterScope - * @return mixed - */ - public function getLastNotificationByCategory($category, $toId, $entity, Closure $filterScope = null) - { - $query = $this->notification - ->wherePolymorphic($toId, $entity) - ->byCategory($category) - ->orderBy('created_at', 'desc'); - - $query = $this->applyFilter($filterScope, $query); - - return $query->first(); - } - - /** - * Apply scope filters. - * - * @param Closure $filterScope - * @param $query - */ - protected function applyFilter(Closure $filterScope = null, $query) - { - if (! $filterScope) { - return $query; - } - - $filterScope($query); - - return $query; - } - - /** - * Retrive all notifications, in a stack. - * You can also limit the number of - * Notifications if you don't, it will get all. - * - * @param $stackId - * @param null $limit - * @param int|null $paginate - * @param string $orderDate - * @param Closure $filterScope - * @return mixed - */ - public function getStack( - $stackId, - $limit = null, - $paginate = null, - $orderDate = 'desc', - Closure $filterScope = null - ) { - $query = $this->notification->with('body', 'from', 'to') - ->byStack($stackId) - ->orderBy('read', 'ASC') - ->orderBy('created_at', $orderDate); - - if ($limit && ! $paginate) { - $query->limit($limit); - } - - $query = $this->applyFilter($filterScope, $query); - - if (is_int(intval($paginate)) && $paginate) { - return $query->paginate($limit); - } - - return $query->get(); - } -} diff --git a/src/Notifynder/Notifynder.php b/src/Notifynder/Notifynder.php deleted file mode 100755 index c210c8b..0000000 --- a/src/Notifynder/Notifynder.php +++ /dev/null @@ -1,320 +0,0 @@ -send() if u pass 'sendCustom' - * it will be like $notifynder->sendCustom(). - * - * @param $customSenderName - * @return $this - */ - public function dispatchWith($customSenderName); -} diff --git a/src/Notifynder/NotifynderManager.php b/src/Notifynder/NotifynderManager.php deleted file mode 100755 index 67cdba1..0000000 --- a/src/Notifynder/NotifynderManager.php +++ /dev/null @@ -1,652 +0,0 @@ -notifynderCategory = $notifynderCategory; - $this->notifynderSender = $notifynderSender; - $this->notification = $notification; - $this->notifynderDispatcher = $notifynderDispatcher; - $this->notifynderGroup = $notifynderGroup; - - parent::__construct($notifynderCategory); - } - - /** - * Set the category of the - * notification. - * - * @param $name - * @return $this - */ - public function category($name) - { - // Check if the category is lazy loaded - if ($this->isLazyLoaded($name)) { - // Yes it is, split out the value from the array - $this->defaultCategory = $this->getCategoriesContainer($name); - - // set category on the builder - parent::category($this->defaultCategory->id); - - return $this; - } - - // Otherwise ask to the db and give me the right category - // associated with this name. If the category is not found - // it throw CategoryNotFoundException - $category = $this->notifynderCategory->findByName($name); - - $this->defaultCategory = $category; - - // Set the category on the array - $this->setCategoriesContainer($name, $category); - - // set category on the builder - parent::category($category->id); - - return $this; - } - - /** - * Define an entity when Notifynder is - * used Polymorphically. - * - * @param $name - * @return $this - */ - public function entity($name) - { - $this->entity = $name; - - return $this; - } - - /** - * Add a category. - * - * @param $name - * @param $text - * @return static - */ - public function addCategory($name, $text) - { - return $this->notifynderCategory->add($name, $text); - } - - /** - * Update a category. - * - * @param array $updates - * @param $categoryId - * @return mixed - */ - public function updateCategory(array $updates, $categoryId) - { - return $this->notifynderCategory->update($updates, $categoryId); - } - - /** - * Send notifications - * Both multiple and single. - * - * @param array $info - * @return mixed - */ - public function send($info = []) - { - $info = (count($info) > 0) ? $info : $this->toArray(); - - $notificationSent = $this->notifynderSender->send($info, $this->defaultCategory); - - $this->refresh(); - - return $notificationSent; - } - - /** - * Send immediately the notification - * even if the queue is enabled. - * - * @param array $info - * @return mixed - */ - public function sendNow($info = []) - { - $info = (count($info) > 0) ? $info : $this->toArray(); - - $notificationsSent = $this->notifynderSender->sendNow($info, $this->defaultCategory); - - $this->refresh(); - - return $notificationsSent; - } - - /** - * Send One notification. - * - * @param array $info - * @return mixed - */ - public function sendOne($info = []) - { - $info = (count($info) > 0) ? $info : $this->toArray(); - - $notificationSent = $this->notifynderSender->sendOne($info, $this->defaultCategory); - - $this->refresh(); - - return $notificationSent; - } - - /** - * Send multiple notifications. - * - * @param array $info - * @return Senders\SendMultiple - */ - public function sendMultiple($info = []) - { - $info = (count($info) > 0) ? $info : $this->toArray(); - - $notificationsSent = $this->notifynderSender->sendMultiple($info, $this->defaultCategory); - - $this->refresh(); - - return $notificationsSent; - } - - /** - * Send a group of notifications. - * - * @param $groupName - * @param $info - * @return mixed - */ - public function sendGroup($groupName, $info = []) - { - $info = (count($info) > 0) ? $info : $this->toArray(); - - $notificationsSent = $this->notifynderSender->sendGroup($this, $groupName, $info); - - $this->refresh(); - - return $notificationsSent; - } - - /** - * Read one notification. - * - * @param $notificationId - * @return bool|Models\Notification - */ - public function readOne($notificationId) - { - return $this->notification->readOne($notificationId); - } - - /** - * Read notification in base the number - * Given. - * - * @param $toId - * @param $numbers - * @param string $order - * @return mixed - */ - public function readLimit($toId, $numbers, $order = 'ASC') - { - $notification = $this->notification->entity($this->entity); - - return $notification->readLimit($toId, $numbers, $order); - } - - /** - * Read all notifications of the given - * entity. - * - * @param $toId - * @return Number - */ - public function readAll($toId) - { - $notifications = $this->notification->entity($this->entity); - - return $notifications->readAll($toId); - } - - /** - * Delete a single notification. - * - * @param $notificationId - * @return bool - */ - public function delete($notificationId) - { - return $this->notification->delete($notificationId); - } - - /** - * Delete number of notifications - * specified of the given entity. - * - * @param $toId - * @param $number - * @param string $order - * @return mixed - */ - public function deleteLimit($toId, $number, $order = 'ASC') - { - $notifications = $this->notification->entity($this->entity); - - return $notifications->deleteLimit($toId, $number, $order); - } - - /** - * Delete all notifications - * of the the given entity. - * - * @param $toId - * @return bool - */ - public function deleteAll($toId) - { - $notifications = $this->notification->entity($this->entity); - - return $notifications->deleteAll($toId); - } - - /** - * Delete All notifications from a - * defined category. - * - * @param $categoryName string - * @param $expired Bool - * @return bool - */ - public function deleteByCategory($categoryName, $expired = false) - { - return $this->notification->deleteByCategory($categoryName, $expired); - } - - /** - * Get Notifications not read - * of the given entity. - * - * @param $toId - * @param null $limit - * @param null|int $paginate - * @param string $order - * @param Closure $filterScope - * @return mixed - */ - public function getNotRead($toId, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) - { - $notifications = $this->notification->entity($this->entity); - - return $notifications->getNotRead($toId, $limit, $paginate, $order, $filterScope); - } - - /** - * Get all notifications of the - * given entity. - * - * @param $toId - * @param null $limit - * @param int|null $paginate - * @param string $order - * @param Closure $filterScope - * @return mixed - */ - public function getAll($toId, $limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null) - { - $notifications = $this->notification->entity($this->entity); - - return $notifications->getAll($toId, $limit, $paginate, $order, $filterScope); - } - - /** - * Get number of notification not read - * of the given entity. - * - * @param $toId - * @param Closure $filterScope - * @return mixed - */ - public function countNotRead($toId, Closure $filterScope = null) - { - $notifications = $this->notification->entity($this->entity); - - return $notifications->countNotRead($toId, $filterScope); - } - - /** - * Find Notification by ID. - * - * @param $notificationId - * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static - */ - public function findNotificationById($notificationId) - { - return $this->notification->find($notificationId); - } - - /** - * Get last notification of the given - * entity, second parameter can filter by - * category. - * - * @param $toId - * @param null $category - * @param Closure $filterScope - * @return mixed - */ - public function getLastNotification($toId, $category = null, Closure $filterScope = null) - { - $notification = $this->notification->entity($this->entity); - - if (is_null($category)) { - return $notification->getLastNotification($toId, $filterScope); - } - - return $notification->getLastNotificationByCategory($category, $toId, $filterScope); - } - - /** - * Add category to a group - * giving the names of them. - * - * @param $groupName - * @param $categoryName - * @return mixed - */ - public function addCategoryToGroupByName($groupName, $categoryName) - { - return $this->notifynderGroup->addCategoryToGroupByName($groupName, $categoryName); - } - - /** - * Add category to a group - * giving the ids of them. - * - * @param $groupId - * @param $categoryId - * @return mixed - */ - public function addCategoryToGroupById($groupId, $categoryId) - { - return $this->notifynderGroup->addCategoryToGroupById($groupId, $categoryId); - } - - /** - * Add categories to a group having as first parameter - * the name of the group, and others as name - * categories. - * - * @return mixed - */ - public function addCategoriesToGroup() - { - return $this->notifynderGroup->addMultipleCategoriesToGroup(func_get_args()); - } - - /** - * Fire method for fire listeners - * of logic. - * - * @param string $key - * @param string $categoryName - * @param mixed|null $values - * @return mixed|null - */ - public function fire($key, $categoryName, $values = []) - { - return $this->notifynderDispatcher->sendWith($this->eventSender) - ->fire($this, $key, $categoryName, $values); - } - - /** - * Associate events to categories. - * - * @param $data - * @param array $delegation - * @return mixed - */ - public function delegate(array $delegation, $data = []) - { - return $this->notifynderDispatcher->delegate($this, $data, $delegation); - } - - /** - * Boot Listeners. - * - * @param array $listeners - */ - public function bootListeners(array $listeners) - { - $this->notifynderDispatcher->boot($listeners); - } - - /** - * Get instance of the notifynder builder. - * - * @return NotifynderBuilder - */ - public function builder() - { - return new parent($this->notifynderCategory); - } - - /** - * Extend a custom sender method. - * - * @param $name - * @param callable $registrar - * @return $this - */ - public function extend($name, $registrar) - { - if (! starts_with($name, 'send')) { - $error = 'The sender method must start with [send]'; - throw new InvalidArgumentException($error); - } - - $this->notifynderSender->extend($name, $registrar); - - return $this; - } - - /** - * Check if the category is eager Loaded. - * - * @param $name - * @return bool - */ - protected function isLazyLoaded($name) - { - return array_key_exists($name, $this->categoriesContainer); - } - - /** - * Return the Id of the category. - * - * @return mixed - */ - public function id() - { - return $this->defaultCategory->id; - } - - /** - * Push a category in the categoriesContainer - * property. - * - * @param $name - * @param array $categoriesContainer - */ - protected function setCategoriesContainer($name, $categoriesContainer) - { - $this->categoriesContainer[$name] = $categoriesContainer; - } - - /** - * Get the categoriesContainer property. - * - * @param $name - * @return array - */ - public function getCategoriesContainer($name) - { - return $this->categoriesContainer[$name]; - } - - /** - * Define which method - * the event dispatcher has - * to send the notifications. - * - * @param $customSenderName - * @return $this - */ - public function dispatchWith($customSenderName) - { - $this->eventSender = $customSenderName; - - return $this; - } - - /** - * Call the custom sender method. - * - * @param $name - * @param $arguments - * @return void|mixed - */ - public function __call($name, $arguments) - { - if (starts_with($name, 'send')) { - $arguments = (isset($arguments[0])) ? $arguments[0] : $this->toArray(); - - $notificationsSent = $this->notifynderSender->customSender($name, $arguments); - $this->refresh(); - - return $notificationsSent; - } - - $error = "method [$name] not found in the class ".self::class; - throw new BadMethodCallException($error); - } - - /** - * Set builder properties - * When setting dynamic properties. - * - * @param $name - * @param $value - */ - public function __set($name, $value) - { - $this->offsetSet($name, $value); - } - - /** - * Get property from the - * builder. - * - * @param $name - * @return mixed - */ - public function __get($name) - { - return $this->offsetGet($name); - } -} diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 9e22457..7b01c66 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -2,64 +2,21 @@ namespace Fenos\Notifynder; -use Fenos\Notifynder\Artisan\CreateCategory; -use Fenos\Notifynder\Artisan\DeleteCategory; -use Fenos\Notifynder\Artisan\CreateGroup; -use Fenos\Notifynder\Artisan\PushCategoryToGroup; -use Fenos\Notifynder\Builder\NotifynderBuilder; -use Fenos\Notifynder\Categories\CategoryRepository; -use Fenos\Notifynder\Categories\CategoryManager; -use Fenos\Notifynder\Contracts\CategoryDB; -use Fenos\Notifynder\Contracts\NotificationDB; -use Fenos\Notifynder\Contracts\NotifynderCategory; -use Fenos\Notifynder\Contracts\NotifynderDispatcher; -use Fenos\Notifynder\Contracts\NotifynderGroup; -use Fenos\Notifynder\Contracts\NotifynderGroupCategoryDB; -use Fenos\Notifynder\Contracts\NotifynderGroupDB; -use Fenos\Notifynder\Contracts\NotifynderNotification; -use Fenos\Notifynder\Contracts\NotifynderSender; -use Fenos\Notifynder\Contracts\NotifynderTranslator; -use Fenos\Notifynder\Contracts\StoreNotification; -use Fenos\Notifynder\Groups\GroupManager; -use Fenos\Notifynder\Groups\GroupCategoryRepository; -use Fenos\Notifynder\Groups\GroupRepository; -use Fenos\Notifynder\Handler\Dispatcher; -use Fenos\Notifynder\Models\Notification; -use Fenos\Notifynder\Models\NotificationCategory; -use Fenos\Notifynder\Models\NotificationGroup; -use Fenos\Notifynder\Notifications\NotificationManager; -use Fenos\Notifynder\Notifications\NotificationRepository; -use Fenos\Notifynder\Parsers\ArtisanOptionsParser; -use Fenos\Notifynder\Parsers\NotifynderParser; -use Fenos\Notifynder\Senders\SenderFactory; -use Fenos\Notifynder\Senders\SenderManager; -use Fenos\Notifynder\Translator\Compiler; -use Fenos\Notifynder\Translator\TranslatorManager; -use Illuminate\Container\Container; +use Fenos\Notifynder\Collections\Config; +use Fenos\Notifynder\Contracts\ConfigContract; +use Fenos\Notifynder\Contracts\NotifynderContract; +use Fenos\Notifynder\Managers\NotifynderManager; use Illuminate\Support\ServiceProvider; class NotifynderServiceProvider extends ServiceProvider { - /** - * Register Bindings. - */ public function register() { - $this->notifynder(); - $this->senders(); - $this->notifications(); - $this->categories(); - $this->builder(); - $this->groups(); - $this->translator(); - $this->events(); - $this->contracts(); - $this->artisan(); + $this->bindContracts(); + $this->bindConfig(); + $this->bindNotifynder(); } - /* - * Boot the publishing config - */ public function boot() { $this->config(); @@ -67,195 +24,42 @@ public function boot() } /** - * Bind Notifynder. + * Bind contracts. */ - protected function notifynder() + protected function bindContracts() { - $this->app->singleton('notifynder', function ($app) { - return new NotifynderManager( - $app['notifynder.category'], - $app['notifynder.sender'], - $app['notifynder.notification'], - $app['notifynder.dispatcher'], - $app['notifynder.group'] - ); - }); - - // Register Facade - $this->app->alias('notifynder', 'Notifynder'); - } - - /** - * Bind Notifynder Categories to IoC. - */ - protected function categories() - { - $this->app->singleton('notifynder.category', function ($app) { - return new CategoryManager( - $app->make('notifynder.category.repository') - ); - }); - - $this->app->singleton('notifynder.category.repository', function () { - return new CategoryRepository( - new NotificationCategory() - ); - }); - } - - /** - * Bind the notifications. - */ - protected function notifications() - { - $this->app->singleton('notifynder.notification', function ($app) { - return new NotificationManager( - $app['notifynder.notification.repository'] - ); - }); - - $this->app->singleton('notifynder.notification.repository', function ($app) { - $notificationModel = $app['config']->get('notifynder.notification_model'); - $notificationInstance = $app->make($notificationModel); - - return new NotificationRepository( - $notificationInstance, - $app['db'] - ); - }); - - // Inject configs when model is resolved - $this->app->resolving(Notification::class, function (Notification $object, $app) { - $fillable = $app['config']->get('notifynder.additional_fields.fillable', []); - $object->fillable(array_merge($object->getFillable(), $fillable)); - }); - - // Default store notification - $this->app->bind('notifynder.store', 'notifynder.notification.repository'); - } - - /** - * Bind Translator. - */ - protected function translator() - { - $this->app->singleton('notifynder.translator', function ($app) { - return new TranslatorManager( - $app['notifynder.translator.compiler'], - $app['config'] - ); - }); - - $this->app->singleton('notifynder.translator.compiler', function ($app) { - return new Compiler( - $app['filesystem.disk'] - ); - }); - } - - /** - * Bind Senders. - */ - protected function senders() - { - $this->app->singleton('notifynder.sender', function ($app) { - return new SenderManager( - $app['notifynder.sender.factory'], - $app['notifynder.store'], - $app[Container::class] - ); - }); - - $this->app->singleton('notifynder.sender.factory', function ($app) { - return new SenderFactory( - $app['notifynder.group'], - $app['notifynder.category'] - ); - }); + $this->app->bind(NotifynderContract::class, 'notifynder'); + $this->app->bind(ConfigContract::class, 'notifynder.config'); } /** - * Bind Dispatcher. + * Bind notifynder config. */ - protected function events() + protected function bindConfig() { - $this->app->singleton('notifynder.dispatcher', function ($app) { - return new Dispatcher( - $app['events'] - ); + $this->app->singleton('notifynder.config', function ($app) { + return new Config(); }); } /** - * Bind Groups. + * Bind notifynder manager. */ - protected function groups() + protected function bindNotifynder() { - $this->app->singleton('notifynder.group', function ($app) { - return new GroupManager( - $app['notifynder.group.repository'], - $app['notifynder.group.category'] - ); - }); - - $this->app->singleton('notifynder.group.repository', function () { - return new GroupRepository( - new NotificationGroup() - ); - }); - - $this->app->singleton('notifynder.group.category', function ($app) { - return new GroupCategoryRepository( + $this->app->singleton('notifynder', function ($app) { + return new NotifynderManager( $app['notifynder.category'], - new NotificationGroup() - ); - }); - } - - /** - * Bind Builder. - */ - protected function builder() - { - $this->app->singleton('notifynder.builder', function ($app) { - return new NotifynderBuilder( - $app['notifynder.category'] + $app['notifynder.sender'], + $app['notifynder.notification'], + $app['notifynder.dispatcher'], + $app['notifynder.group'] ); }); - - $this->app->resolving(NotifynderBuilder::class, function (NotifynderBuilder $object, $app) { - $object->setConfig($app['config']); - }); } /** - * Contracts of notifynder. - */ - protected function contracts() - { - // Notifynder - $this->app->bind(Notifynder::class, 'notifynder'); - - // Repositories - $this->app->bind(CategoryDB::class, 'notifynder.category.repository'); - $this->app->bind(NotificationDB::class, 'notifynder.notification.repository'); - $this->app->bind(NotifynderGroupDB::class, 'notifynder.group.repository'); - $this->app->bind(NotifynderGroupCategoryDB::class, 'notifynder.group.category'); - - // Main Classes - $this->app->bind(NotifynderCategory::class, 'notifynder.category'); - $this->app->bind(NotifynderNotification::class, 'notifynder.notification'); - $this->app->bind(NotifynderTranslator::class, 'notifynder.translator'); - $this->app->bind(NotifynderGroup::class, 'notifynder.group'); - - // Store notifications - $this->app->bind(StoreNotification::class, 'notifynder.store'); - $this->app->bind(NotifynderSender::class, 'notifynder.sender'); - $this->app->bind(NotifynderDispatcher::class, 'notifynder.dispatcher'); - } - - /** - * Publish config files. + * Publish config file. */ protected function config() { @@ -264,11 +68,6 @@ protected function config() ]); $this->mergeConfigFrom(__DIR__.'/../config/notifynder.php', 'notifynder'); - - // Set use strict_extra config option, - // you can toggle it in the configuration file - $strictParam = $this->app['config']->get('notifynder.strict_extra', false); - NotifynderParser::setStrictExtra($strictParam); } /** @@ -329,45 +128,4 @@ protected function migrationFilepath($filename) return base_path('/database/migrations/'.$filename); } } - - /** - * Register Artisan commands. - */ - protected function artisan() - { - // Categories - $this->app->singleton('notifynder.artisan.category-add', function ($app) { - return new CreateCategory( - $app['notifynder.category'] - ); - }); - - $this->app->singleton('notifynder.artisan.category-delete', function ($app) { - return new DeleteCategory( - $app['notifynder.category'] - ); - }); - - // Groups - $this->app->singleton('notifynder.artisan.group-add', function ($app) { - return new CreateGroup( - $app['notifynder.group'] - ); - }); - - $this->app->singleton('notifynder.artisan.group-add-categories', function ($app) { - return new PushCategoryToGroup( - $app['notifynder.group'], - new ArtisanOptionsParser() - ); - }); - - // Register commands - $this->commands([ - 'notifynder.artisan.category-add', - 'notifynder.artisan.category-delete', - 'notifynder.artisan.group-add', - 'notifynder.artisan.group-add-categories', - ]); - } } diff --git a/src/Notifynder/Parsers/ArtisanOptionsParser.php b/src/Notifynder/Parsers/ArtisanOptionsParser.php deleted file mode 100755 index 5827324..0000000 --- a/src/Notifynder/Parsers/ArtisanOptionsParser.php +++ /dev/null @@ -1,56 +0,0 @@ - $field) { - // Example: - // name:string:nullable => ['name', 'string', 'nullable'] - // name:string(15):nullable - $chunks = preg_split('/\s?:\s?/', $field, null); - - // The first item will be our property - $property = array_shift($chunks); - - $args = null; - - // Finally, anything that remains will - // be our decorators - $decorators = $chunks; - - $parsed[$index] = $property; - - if (isset($args)) { - $parsed[$index]['args'] = $args; - } - if ($decorators) { - $parsed[$index]['decorators'] = $decorators; - } - } - - return $parsed; - } -} diff --git a/src/Notifynder/Parsers/NotifynderParser.php b/src/Notifynder/Parsers/NotifynderParser.php deleted file mode 100755 index 5b0aa7e..0000000 --- a/src/Notifynder/Parsers/NotifynderParser.php +++ /dev/null @@ -1,169 +0,0 @@ -extraToArray($item['extra']); - $specialValues = $this->getValues($body); - - if (count($specialValues) > 0) { - $specialValues = array_filter($specialValues, function ($value) { - return starts_with($value, 'extra.') || starts_with($value, 'to.') || starts_with($value, 'from.'); - }); - - foreach ($specialValues as $replacer) { - $replace = $this->mixedGet($item, $replacer); - if (empty($replace) && static::$strictMode) { - $error = "the following [$replacer] param required from your category it's missing. Did you forget to store it?"; - throw new ExtraParamsException($error); - } - $body = $this->replaceBody($body, $replace, $replacer); - } - } - - return $body; - } - - /** - * Set strict mode. - * if it's enabled then will throws exceptions - * when extra params will not be parsed correctly - * will be handy in development. - * - * @param bool|true $set - */ - public static function setStrictExtra($set = true) - { - static::$strictMode = $set; - } - - /** - * Get the values between {} - * and return an array of it. - * - * @param $body - * @return mixed - */ - protected function getValues($body) - { - $values = []; - preg_match_all(self::RULE, $body, $values); - - return $values[1]; - } - - /** - * Trying to transform extra in from few data types - * to array type. - * - * @param $extra - * @return array|mixed - */ - protected function extraToArray($extra) - { - if ($this->isJson($extra)) { - $extra = json_decode($extra, true); - - return $extra; - } elseif ($extra instanceof ExtraParams) { - $extra = $extra->toArray(); - - return $extra; - } - } - - /** - * Replace body of the category. - * - * @param $body - * @param $replacer - * @param $valueMatch - * @return mixed - */ - protected function replaceBody($body, $valueMatch, $replacer) - { - $body = str_replace('{'.$replacer.'}', $valueMatch, $body); - - return $body; - } - - /** - * Check if is a json string. - * - * @param $value - * @return bool - */ - protected function isJson($value) - { - if (! is_string($value)) { - return false; - } - - json_decode($value); - - return json_last_error() == JSON_ERROR_NONE; - } - - /** - * Get a value by dot-key of an array, object or mix of both. - * - * @param array|object $object - * @param string $key - * @param null $default - * @return mixed - */ - protected function mixedGet($object, $key, $default = null) - { - if (is_null($key) || trim($key) == '') { - return ''; - } - - foreach (explode('.', $key) as $segment) { - if (is_object($object) && isset($object->{$segment})) { - $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { - $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { - $object = $object->getAttribute($segment); - } elseif (is_array($object) && array_key_exists($segment, $object)) { - $object = array_get($object, $segment, $default); - } else { - return value($default); - } - } - - return $object; - } -} diff --git a/src/Notifynder/Senders/SendGroup.php b/src/Notifynder/Senders/SendGroup.php deleted file mode 100755 index fca9baa..0000000 --- a/src/Notifynder/Senders/SendGroup.php +++ /dev/null @@ -1,82 +0,0 @@ -info = $info; - $this->nameGroup = $nameGroup; - $this->notifynderGroup = $notifynderGroup; - $this->notifynderCategory = $notifynderCategory; - } - - /** - * Send group notifications. - * - * @param StoreNotification $sender - * @return mixed - */ - public function send(StoreNotification $sender) - { - // Get group - $group = $this->notifynderGroup->findByName($this->nameGroup); - - // Categories - $categoriesAssociated = $group->categories; - - // Send a notification for each category - foreach ($categoriesAssociated as $category) { - // Category name - $categoryModel = $this->notifynderCategory->findByName($category->name); - - $notification = array_merge( - ['category_id' => $categoryModel->id], - $this->info - ); - - $sender->storeSingle($notification); - } - - return $group; - } -} diff --git a/src/Notifynder/Senders/SendMultiple.php b/src/Notifynder/Senders/SendMultiple.php deleted file mode 100755 index f0252a6..0000000 --- a/src/Notifynder/Senders/SendMultiple.php +++ /dev/null @@ -1,38 +0,0 @@ -infoNotifications = $infoNotifications; - } - - /** - * Send multiple notifications. - * - * @param StoreNotification $sender - * @return mixed - */ - public function send(StoreNotification $sender) - { - return $sender->storeMultiple($this->infoNotifications); - } -} diff --git a/src/Notifynder/Senders/SendOne.php b/src/Notifynder/Senders/SendOne.php deleted file mode 100755 index 092e837..0000000 --- a/src/Notifynder/Senders/SendOne.php +++ /dev/null @@ -1,60 +0,0 @@ -infoNotification = $infoNotification; - } - - /** - * Send Single notification. - * - * @param StoreNotification $sender - * @return mixed - */ - public function send(StoreNotification $sender) - { - $this->hasCategory(); - - return $sender->storeSingle($this->infoNotification); - } - - /** - * Check if the category of the notification has been - * specified in the array of information. - * - * @return bool - * @throws \Fenos\Notifynder\Exceptions\CategoryNotFoundException - */ - protected function hasCategory() - { - if (! array_key_exists('category_id', $this->infoNotification)) { - $error = 'Category not found please provide one, - you can not store a notification without category id'; - - throw new CategoryNotFoundException($error); - } - - return true; - } -} diff --git a/src/Notifynder/Senders/SenderFactory.php b/src/Notifynder/Senders/SenderFactory.php deleted file mode 100755 index 5a795cc..0000000 --- a/src/Notifynder/Senders/SenderFactory.php +++ /dev/null @@ -1,120 +0,0 @@ -notifynderGroup = $notifynderGroup; - $this->notifynderCategory = $notifynderCategory; - } - - /** - * Get the right sender when the data is - * passed. - * - * @param array $infoNotifications - * @param $category - * @return SendMultiple|SendOne - */ - public function getSender($infoNotifications, $category = null) - { - if ($infoNotifications instanceof NotifynderBuilder) { - $infoNotifications = $infoNotifications->toArray(); - } - - // if the array is multidimensional - // it means that we want to send - // multiple notifications - if ($this->isMultiArray($infoNotifications)) { - return $this->sendMultiple($infoNotifications); - } else { - return $this->sendSingle($infoNotifications, $category); - } - } - - /** - * Send Single Notification Sender. - * - * @param array $infoNotifications - * @param $category - * @return SendOne - */ - public function sendSingle(array $infoNotifications, $category) - { - return new SendOne($infoNotifications, $category); - } - - /** - * Send Multiple Notification Sender. - * - * @param array $infoNotifications - * @return SendMultiple - */ - public function sendMultiple(array $infoNotifications) - { - return new SendMultiple($infoNotifications); - } - - /** - * Get the the send group instance. - * - * @param string $groupName - * @param array | \Closure $info - * @return SendGroup - */ - public function sendGroup($groupName, array $info) - { - return new SendGroup( - $this->notifynderGroup, - $this->notifynderCategory, - $groupName, - $info - ); - } - - /** - * Check if the array passed is - * multidimensional. - * - * @param $arr - * @return bool - */ - protected function isMultiArray(array $arr) - { - $rv = array_filter($arr, 'is_array'); - if (count($rv) > 0) { - return true; - } - - return false; - } -} diff --git a/src/Notifynder/Senders/SenderManager.php b/src/Notifynder/Senders/SenderManager.php deleted file mode 100755 index d525a4b..0000000 --- a/src/Notifynder/Senders/SenderManager.php +++ /dev/null @@ -1,199 +0,0 @@ -senderFactory = $senderFactory; - $this->storeNotification = $storeNotification; - $this->container = $container; - } - - /** - * Send any notifications. - * - * @param array $info - * @param null $category - * @return mixed - */ - public function send($info, $category = null) - { - return $this->sendNow($info, $category); - } - - /** - * Send now whatever data passed. - * - * @param array $info - * @param $category - * @return mixed - */ - public function sendNow($info, $category = null) - { - $sender = $this->senderFactory->getSender($info, $category); - - return $sender->send($this->storeNotification); - } - - /** - * Send one method to get fully working - * older version. - * - * @param $info - * @param $category - * @return SendOne - */ - public function sendOne($info, $category = null) - { - return $this->senderFactory->sendSingle($info, $category) - ->send($this->storeNotification, $category); - } - - /** - * Send Multiple method to get fully working - * older version. - * - * @param $info - * @return SendMultiple - */ - public function sendMultiple($info) - { - return $this->senderFactory->sendMultiple($info) - ->send($this->storeNotification); - } - - /** - * Send a group of notifications - * at once. - * - * @param $groupName - * @param array $info - * @return mixed - */ - public function sendGroup($groupName, $info = []) - { - return $this->senderFactory->sendGroup( - $groupName, - $info - )->send($this->storeNotification); - } - - /** - * This method allow to Extend - * notifynder with custom sender. - * - * @param $name - * @param callable $extendSender - * @return $this - */ - public function extend($name, $extendSender) - { - $this->senders[$name] = $extendSender; - - return $this; - } - - /** - * Call a custom method. - * - * @param $customMethod - * @param $notification - * @return mixed - */ - public function customSender($customMethod, $notification) - { - if (array_key_exists($customMethod, $this->senders)) { - - // get the extended method - $extendedSender = $this->senders[$customMethod]; - - // If is a closure means that i'll return an instance - // with the - if ($extendedSender instanceof Closure) { - - // I invoke the closure expecting an Instance of a custom - // Sender - $invoker = call_user_func_array($extendedSender, [$notification, $this->container]); - - // If the invoker is a custom sender - // then I invoke it passing the sender class - if ($invoker instanceof Sender) { - return $invoker->send($this); - } - - // If the dev is attempting to create a custom - // way of storing notifications then - // i'll pass the store notification contract - if ($invoker instanceof DefaultSender) { - return $invoker->send($this->storeNotification); - } - } - - $error = 'The extension must be an instance of Closure'; - throw new LogicException($error); - } - - $error = "The method $customMethod does not exists on the class ".get_class($this); - throw new BadMethodCallException($error); - } - - /** - * When calling a not existing method - * try to resolve with an extended. - * - * @param $name - * @param $arguments - * @return mixed - */ - public function __call($name, $arguments) - { - if (isset($arguments[0])) { - return $this->customSender($name, $arguments[0]); - } - - $error = 'No argument passed to the custom sender, - please provide notifications array'; - throw new BadMethodCallException($error); - } -} diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php new file mode 100755 index 0000000..477cd14 --- /dev/null +++ b/src/Notifynder/Traits/Notifable.php @@ -0,0 +1,14 @@ +getNotificationModel(); + if (notifynder_config()->isPolymorphic()) { + return $this->morphMany($model, 'to'); + } + return $this->hasMany($model, 'to_id'); + } +} diff --git a/src/Notifynder/Translator/Compiler.php b/src/Notifynder/Translator/Compiler.php deleted file mode 100755 index 82ecf83..0000000 --- a/src/Notifynder/Translator/Compiler.php +++ /dev/null @@ -1,97 +0,0 @@ -files = $files; - } - - /** - * Get cached file. - * - * @return string - */ - public function getFilePath() - { - return $this->getCompiledPath('notification_categories'); - } - - /** - * Get the path to the compiled version of a view. - * - * @param string $filename - * @return string - */ - public function getCompiledPath($filename) - { - return $this->cachePath().'/'.md5($filename); - } - - /** - * Determine if the view at the given path is expired. - * - * @return bool - */ - public function isExpired() - { - $compiled = $this->getFilePath(); - - // If the compiled file doesn't exist we will indicate that the view is expired - // so that it can be re-compiled. Else, we will verify the last modification - // of the views is less than the modification times of the compiled views. - if (! $this->cachePath() || ! $this->files->exists($compiled)) { - return true; - } - - $lastModified = $this->files->lastModified($this->getFilePath()); - - return $lastModified >= $this->files->lastModified($compiled); - } - - /** - * Get cache path. - * - * @return string - */ - protected function cachePath() - { - return storage_path('app/notifynder'); - } - - /** - * Cache the file in json format. - * - * @param array $contents - * @return bool|int - */ - public function cacheFile(array $contents) - { - $contents = json_encode($contents); - - return $this->files->put($this->getFilePath(), $contents); - } -} diff --git a/src/Notifynder/Translator/TranslatorManager.php b/src/Notifynder/Translator/TranslatorManager.php deleted file mode 100755 index df5a04a..0000000 --- a/src/Notifynder/Translator/TranslatorManager.php +++ /dev/null @@ -1,133 +0,0 @@ - [ - * 'name.category' => 'text to {parse value} translate' - * ] - * ] - */ -class TranslatorManager implements NotifynderTranslator -{ - /** - * @var Compiler - */ - protected $compiler; - - /** - * @var Repository - */ - private $config; - - /** - * @param Compiler $compiler - * @param Repository $config - */ - public function __construct(Compiler $compiler, Repository $config) - { - $this->compiler = $compiler; - $this->config = $config; - } - - /** - * Translate the given category. - * - * @param $language - * @param $nameCategory - * @return mixed - * @throws NotificationLanguageNotFoundException - * @throws NotificationTranslationNotFoundException - */ - public function translate($language, $nameCategory) - { - $translations = $this->getLanguage($language); - - if (array_key_exists($nameCategory, $translations)) { - return $translations[$nameCategory]; - } - - $error = 'Translation not found'; - throw new NotificationTranslationNotFoundException($error); - } - - /** - * Get selected language of translations. - * - * @param $language - * @return mixed - * @throws NotificationLanguageNotFoundException - */ - public function getLanguage($language) - { - $translations = $this->getTranslations(); - - if (array_key_exists($language, $translations)) { - return $translations[$language]; - } - - $error = 'Language Not Found'; - throw new NotificationLanguageNotFoundException($error); - } - - /** - * Get translations. - * - * @return array|mixed - */ - public function getTranslations() - { - // File cached path - $filePath = $this->compiler->getFilePath(); - - // If the file exists - if (file_exists($filePath)) { - // Check if is not expired - if (! $this->compiler->isExpired()) { - // Return the cached file in - // an array - return json_decode( - file_get_contents($filePath) - ); - } - } - - return $this->cacheFromConfig(); - } - - /** - * Get the translations from the - * array of the config file and it - * will cache them. - * - * @return array - */ - protected function cacheFromConfig() - { - // If is expire then I retrieve directly the array - $fileTranslation = $this->config->get( - 'notifynder.translations' - ); - - // I put the edited content in the cached file - $this->compiler->cacheFile($fileTranslation); - - // return the translations - return $fileTranslation; - } -} diff --git a/src/config/notifynder.php b/src/config/notifynder.php index cf70da4..4ad476e 100755 --- a/src/config/notifynder.php +++ b/src/config/notifynder.php @@ -27,7 +27,7 @@ * With the path / NameSpace of your model and extend it * with Fenos\Notifynder\Models\Notification */ - 'notification_model' => 'Fenos\Notifynder\Models\Notification', + 'notification_model' => \Fenos\Notifynder\Models\Notification::class, /* * Coordinating a lots notifications that require extra params diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/TestCaseDB.php b/tests/TestCaseDB.php deleted file mode 100755 index e106474..0000000 --- a/tests/TestCaseDB.php +++ /dev/null @@ -1,87 +0,0 @@ -app->make('Illuminate\Contracts\Console\Kernel'); - - app('db')->beginTransaction(); - - $this->migrate($artisan); - $this->migrate($artisan, '/../../../../tests/migrations'); - - // Set up the User Test Model - app('config')->set('notifynder.notification_model', 'Fenos\Notifynder\Models\Notification'); - app('config')->set('notifynder.model', 'Fenos\Tests\Models\User'); - } - - /** - * Define environment setup. - * - * @param \Illuminate\Foundation\Application $app - * @return void - */ - protected function getEnvironmentSetUp($app) - { - $app['config']->set('database.default', 'testbench'); - $app['config']->set('database.connections.testbench', [ - 'driver' => 'sqlite', - 'database' => ':memory:', - 'prefix' => '', - ]); - } - - /** - * Rollback transactions after each test. - */ - public function tearDown() - { - app('db')->rollback(); - } - - /** - * Get application timezone. - * - * @param \Illuminate\Foundation\Application $app - * @return string|null - */ - protected function getApplicationTimezone($app) - { - return 'UTC'; - } - - /** - * Migrate the migrations files. - * - * @param $artisan - * @param string $path - */ - private function migrate($artisan, $path = '/../../../../src/migrations') - { - $artisan->call('migrate', [ - '--database' => 'testbench', - '--path' => $path, - ]); - } -} diff --git a/tests/factories/factories.php b/tests/factories/factories.php deleted file mode 100755 index 33b2583..0000000 --- a/tests/factories/factories.php +++ /dev/null @@ -1,32 +0,0 @@ - $faker->name, - 'text' => 'test notification', -]); - -$factory('Fenos\Tests\Models\User', [ - - 'name' => $faker->name, - 'surname' => $faker->lastName, -]); - -$factory('Fenos\Notifynder\Models\Notification', [ - - 'from_id' => 'factory:Fenos\Tests\Models\User', - 'from_type' => 'Fenos\Tests\Models\User', - 'to_id' => 'factory:Fenos\Tests\Models\User', - 'to_type' => 'Fenos\Tests\Models\User', - 'category_id' => 'factory:Fenos\Notifynder\Models\NotificationCategory', - 'url' => $faker->url, - 'extra' => json_encode(['exta.name' => $faker->name]), - 'read' => 0, - 'expire_time' => null, - 'created_at' => $faker->dateTime, - 'updated_at' => $faker->dateTime, -]); - -$factory('Fenos\Notifynder\Models\NotificationGroup', [ - 'name' => $faker->name, -]); diff --git a/tests/integration/CreateModels.php b/tests/integration/CreateModels.php deleted file mode 100755 index e6c9a3e..0000000 --- a/tests/integration/CreateModels.php +++ /dev/null @@ -1,67 +0,0 @@ - $this->to['id'], - 'to_type' => $this->to['type'], - 'read' => 0, - ]; - - return Factory::times($this->multiNotificationsNumber) - ->create(Notification::class, array_merge($to_entity, $data)); - } - - /** - * @param array $data - * @return mixed - */ - protected function createUser(array $data = []) - { - return Factory::create('Fenos\Tests\Models\User', $data); - } -} diff --git a/tests/integration/CustomSender.php b/tests/integration/CustomSender.php deleted file mode 100755 index 60802df..0000000 --- a/tests/integration/CustomSender.php +++ /dev/null @@ -1,42 +0,0 @@ -notifications = $notifications; - $this->notifynder = $notifynder; - } - - /** - * Send notification. - * - * @param NotifynderSender $sender - * @return mixed - */ - public function send(NotifynderSender $sender) - { - // dd($storeNotification); - return $sender->send($this->notifications); - } -} diff --git a/tests/integration/Handler/NotifyEvent.php b/tests/integration/Handler/NotifyEvent.php deleted file mode 100755 index fb32504..0000000 --- a/tests/integration/Handler/NotifyEvent.php +++ /dev/null @@ -1,31 +0,0 @@ -notifynderEvent = $notifynderEvent; - } - - /** - * @return NotifynderEvent - */ - public function getNotifynderEvent() - { - return $this->notifynderEvent; - } -} diff --git a/tests/integration/Handler/NotifynderHandlerTest.php b/tests/integration/Handler/NotifynderHandlerTest.php deleted file mode 100755 index 8438c07..0000000 --- a/tests/integration/Handler/NotifynderHandlerTest.php +++ /dev/null @@ -1,181 +0,0 @@ - 'NotifyUserTest', - ]; - - /** - * User to. - * - * @var User - */ - protected $to; - - /** - * @var User - */ - protected $from; - - /** - * @var Dispatcher - */ - protected $laravelDispatcher; - - /** - * Listen test listeners. - */ - public function setUp() - { - parent::setUp(); - - $this->dispatcher = app('notifynder'); - $this->laravelDispatcher = app('events'); - - // Boot Listeners - $this->dispatcher->bootListeners($this->listeners); - - // Create Users - $this->to = $this->createUser(); - $this->from = $this->createUser(); - - // Create Category - $this->createCategory([ - 'name' => 'activation', - ]); - - $this->createCategory([ - 'name' => 'confirmation', - ]); - } - - /** @test */ - public function it_fire_an_event_sending_a_specific_notification_from_the_handler() - { - $this->dispatcher->fire('notify@userActivated', 'activation'); - - $notification = \Fenos\Notifynder\Models\Notification::all(); - - $this->assertCount(1, $notification); - } - - /** @test */ - public function it_fire_an_event_sending_multiple_notifications() - { - $this->dispatcher->fire('notify@userMultiple', 'activation'); - - $notification = \Fenos\Notifynder\Models\Notification::all(); - - $this->assertCount(2, $notification); - } - - /** @test */ - public function it_delete_2_notification_to_be_sent_trought_the_handler() - { - $this->dispatcher->delegate([ - 'activation' => 'notify@userActivated', - 'confirmation' => 'notify@userMultiple', - ]); - - $notification = \Fenos\Notifynder\Models\Notification::all(); - - $this->assertCount(3, $notification); - } - - /** @test */ - public function it_trigger_an_handler_using_native_laravel_dispatcher() - { - $testListener = [ - NotifyEvent::class => [ - NotifyUserTest::class, - ], - ]; - - // Listen for events as the laravel way - foreach ($testListener as $event => $listeners) { - foreach ($listeners as $listener) { - $this->laravelDispatcher->listen($event, $listener); - } - } - - $notification = $this->laravelDispatcher->fire( - new NotifyEvent(new NotifynderEvent('userActivated')) - ); - - $this->assertEquals('hello', $notification[0]->url); - } -} - -/* -|-------------------------------------------------------------------------- -| NotifyUserTest: Example of Handler -|-------------------------------------------------------------------------- -| NotifyUserTest Class is an handler to test the implementation against it ---------------------------------------------------------------------------*/ - -/** - * Class NotifyUserTest. - */ -class NotifyUserTest extends NotifynderHandler -{ - /** - * Test trigger one notification. - * - * @param NotifynderEvent $event - * @param NotifynderManager $notifynder - * @return mixed - * @throws \Fenos\Notifynder\Exceptions\NotificationBuilderException - */ - public function userActivated(NotifynderEvent $event, NotifynderManager $notifynder) - { - return $notifynder->builder() - ->category('activation') - ->url('hello') - ->from(1) - ->to(2); - } - - /** - * Test send multiple notifications from - * the handler. - * - * @param NotifynderEvent $event - * @param NotifynderManager $notifynder - * @return $this - */ - public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynder) - { - // Retrieve users - $users = [1, 2]; - - return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { - return $builder->category('activation') - ->url('hello') - ->from(1) - ->to($value); - }); - } -} diff --git a/tests/integration/Notifable/NotifableTest.php b/tests/integration/Notifable/NotifableTest.php deleted file mode 100755 index 231d8b3..0000000 --- a/tests/integration/Notifable/NotifableTest.php +++ /dev/null @@ -1,170 +0,0 @@ - 1, - 'type' => 'Fenos\Tests\Models\User', - ]; - - /** - * @var Notification - */ - protected $notification; - - /** - * @var User - */ - protected $user; - - /** - * Set Up Test. - */ - public function setUp() - { - parent::setUp(); - $this->notification = app('notifynder.notification'); - $this->user = Factory::create(User::class); - } - - /** - * @test - */ - public function it_count_notification_not_read() - { - $this->createMultipleNotifications(['read' => 1]); - - $count = $this->user->countNotificationsNotRead(); - - $this->assertEquals(0, $count); - } - - /** - * It read all notifications. - * - * @method readLimitNotifications - * @test - */ - public function it_real_all_notifications() - { - $this->createMultipleNotifications(); - - $read = $this->user->readAllNotifications(); - - $this->assertEquals(10, $read); - } - - /** - * It read limiting amount the of - * notifications. - * - * @method readLimitNotifications - * @test - */ - public function it_read_a_limit_of_notifications() - { - $this->createMultipleNotifications(); - - $read = $this->user->readLimitNotifications(6); - - $this->assertEquals(6, $read); - } - - /** - * It delete limiting the amount of - * notifications. - * - * @method deleteLimitNotifications - * @test - */ - public function it_delete_limit_notifications() - { - $this->createMultipleNotifications(); - - $deleted = $this->user->deleteLimitNotifications(4); - - $this->assertEquals(4, $deleted); - } - - /** - * It delete all notifications. - * - * @method deleteAllNotifications - * @test - */ - public function it_delete_all_notifications() - { - $this->createMultipleNotifications(); - - $deleted = $this->user->deleteAllNotifications(); - - $this->assertEquals($this->multiNotificationsNumber, $deleted); - } - - /** - * Get notifications unread. - * - * @method - * @test - */ - public function it_get_notifications_not_read() - { - // 20 total - $this->createMultipleNotifications(); - $this->createMultipleNotifications(); - $this->user->readLimitNotifications(10); // 10 read - - $getNotificationNotRead = $this->user->getNotificationsNotRead(); - - $this->assertCount(10, $getNotificationNotRead); - } - - /** - * Get all notifications. - * - * @method getNotifications - * @test - */ - public function it_get_all_notification_of_the_current_user() - { - $this->createMultipleNotifications(); - - $notifications = $this->user->getNotifications(); - - $this->assertCount(10, $notifications); - } - - /** - * get the last notification. - * - * @method getLastNotification - * @test - */ - public function it_get_last_notification() - { - $this->createMultipleNotifications(); - - $lastNotification = $this->user->getLastNotification(); - - $notification = Notification::orderBy('created_at', 'desc')->first(); - - $this->assertEquals($notification->id, $lastNotification->id); - } -} diff --git a/tests/integration/Notifications/NotificationTest.php b/tests/integration/Notifications/NotificationTest.php deleted file mode 100755 index 7e80427..0000000 --- a/tests/integration/Notifications/NotificationTest.php +++ /dev/null @@ -1,213 +0,0 @@ - 1, - 'type' => 'Fenos\Tests\Models\User', - ]; - - /** - * Set Up Test. - */ - public function setUp() - { - parent::setUp(); - $this->notification = app('notifynder.notification'); - } - - /** @test */ - public function it_retrieve_notification_with_parsed_body() - { - $extraValues = json_encode(['look' => 'Amazing']); - $category = $this->createCategory(['text' => 'parse this {extra.look} value']); - - $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); - - $notifications = $this->notification->getNotRead($notification->to->id); - - $bodyParsed = 'parse this Amazing value'; - $this->assertEquals($bodyParsed, $notifications[0]->text); - } - - /** @test */ - public function it_retrieve_notification_by_limiting_the_number() - { - $this->createMultipleNotifications(); - - // set polymorphic to true - app('config')->set('notifynder.polymorphic', true); - - $notification = $this->createNotification(['extra' => 'Amazing']); - $this->createMultipleNotifications(['to_id' => $notification->to_id]); - - $notifications = $this->notification->entity($this->to['type']) - ->getAll($notification->to->id, 1); - - $this->assertCount(1, $notifications); - } - - /** @test */ - public function it_retrieve_notification_by_paginating_the_number() - { - app('config')->set('notifynder.polymorphic', false); - $extraValues = json_encode(['look' => 'Amazing']); - - $category = $this->createCategory(['text' => 'parse this {extra.look} value']); - - $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); - $this->createMultipleNotifications(['to_id' => $notification->to_id]); - - $notifications = $this->notification->getNotRead($notification->to->id, 5, 1); - - $this->assertCount(5, $notifications); - } - - /** - * It will query adding the filter scope - * on of the category by name. - * - * @test - */ - public function it_will_query_for_notification_by_category_name() - { - app('config')->set('notifynder.polymorphic', false); - $this->createMultipleNotifications(); - $category = $this->createCategory(['text' => 'parse this {extra.look} value', 'name' => 'text']); - $this->createMultipleNotifications(['category_id' => $category->id]); - - $user = new \Fenos\Tests\Models\User(['id' => $this->to['id']]); - - $notificationByCategory = $user->getNotifications(false, false, 'desc', function ($query) use ($category) { - $query->byCategory('text'); - }); - - $this->assertCount(10, $notificationByCategory); - } - - /** - * It will check that the fillable fields config option are - * allowing to save the model when resolved trough the ioc. - * - * @test - * @group f - */ - public function it_will_check_the_fillable_fields_options_are_allowing_to_save_the_model() - { - app('config')->set('notifynder.additional_fields.fillable', [ - 'icon_type', - ]); - - $model = app(\Fenos\Notifynder\Models\Notification::class); - $fillable = [ - 'to_id', 'to_type', 'from_id', 'from_type', 'category_id', 'read', 'url', 'extra', 'expire_time', 'stack_id', 'icon_type', - ]; - - $this->assertEquals($fillable, $model->getFillable()); - } - - /** @test */ - public function it_retrieve_notification_with_parsed_body_and_multi_dots() - { - $extraValues = json_encode(['look' => 'Amazing', 'user' => ['last' => 'Doe', 'first' => 'John']]); - $category = $this->createCategory(['text' => 'parse this {extra.look} value from {extra.user.first} {extra.user.last}']); - - $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); - - $notifications = $this->notification->getNotRead($notification->to->id); - - $bodyParsed = 'parse this Amazing value from John Doe'; - $this->assertEquals($bodyParsed, $notifications[0]->text); - } - - /** @test */ - public function it_retrieve_notification_with_parsed_body_and_multi_dots_with_objects() - { - $user = new \Fenos\Tests\Models\User(['id' => '1']); - $object = json_decode(json_encode(['last' => 'Doe', 'first' => 'John']), false); - - $this->assertInstanceOf(\Fenos\Tests\Models\User::class, $user); - $this->assertInstanceOf(stdClass::class, $object); - - $extraValues = json_encode(['look' => 'Amazing', 'user' => $user, 'object' => $object]); - $category = $this->createCategory(['text' => 'parse this {extra.look} value from User#{extra.user.id} ({extra.object.first} {extra.object.last})']); - - $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); - - $notifications = $this->notification->getNotRead($notification->to->id); - - $bodyParsed = 'parse this Amazing value from User#1 (John Doe)'; - $this->assertEquals($bodyParsed, $notifications[0]->text); - } - - /** @test */ - public function it_retrieve_notification_with_extraparams_extra() - { - $extraValues = json_encode(['look' => 'Amazing']); - $category = $this->createCategory(['text' => 'parse this {extra.look} value']); - - $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); - - $notifications = $this->notification->getNotRead($notification->to->id); - $extra = $notifications->first()->extra; - - $this->assertCount(1, $notifications); - $this->assertInstanceOf(\Fenos\Notifynder\Notifications\ExtraParams::class, $extra); - $this->assertEquals('Amazing', $extra->look); - } - - /** @test */ - public function it_retrieve_notifications_toarray() - { - $extraValues = json_encode(['look' => 'Amazing']); - $category = $this->createCategory(['text' => 'parse this {extra.look} value']); - - $notification = $this->createNotification(['extra' => $extraValues, 'category_id' => $category->id]); - - $notifications = $this->notification->getNotRead($notification->to->id)->toArray(); - - $this->assertInternalType('array', $notifications); - $this->assertCount(1, $notifications); - $this->assertInternalType('array', $notifications[0]); - $this->assertArrayHasKey('extra', $notifications[0]); - $this->assertInternalType('array', $notifications[0]['extra']); - $this->assertEquals('Amazing', $notifications[0]['extra']['look']); - } - - /** @test */ - public function it_retrieve_notifications_by_stack_id() - { - $text = 'stack body text'; - $category = $this->createCategory(['text' => $text]); - - $this->createMultipleNotifications(['category_id' => $category->id]); - - $notifications = \Fenos\Notifynder\Models\Notification::byStack(1)->get(); - - foreach ($notifications as $notification) { - $this->assertEquals($text, $notification->text); - $this->assertEquals(1, $notification->stack_id); - $this->assertTrue($notification->hasStack()); - } - } -} diff --git a/tests/integration/Notifications/NotifynderTest.php b/tests/integration/Notifications/NotifynderTest.php deleted file mode 100755 index 07c107d..0000000 --- a/tests/integration/Notifications/NotifynderTest.php +++ /dev/null @@ -1,138 +0,0 @@ -notifynder = app('notifynder'); - } - - /** @test */ - public function it_call_an_extended_method() - { - $this->createCategory(['name' => 'customs']); - - $this->notifynder->extend('sendCustom', function ($notification, $app) { - return new CustomDefaultSender($notification, $app->make('notifynder')); - }); - - $notifications = $this->notifynder - ->category('customs') - ->url('w') - ->from(1) - ->to(1) - ->sendCustom(); - - $this->assertEquals('w', $notifications->url); - } - - /** @test */ - public function it_send_a_notification_with_the_new_way() - { - $this->createCategory(['name' => 'custom']); - - $notifications = $this->notifynder - ->category('custom') - ->url('w') - ->from(1) - ->to(1); - - $notifications = $this->notifynder->send($notifications); - $this->assertEquals('w', $notifications->url); - } - - /** @test */ - public function it_send_using_notifynder_as_an_array() - { - $this->createCategory(['name' => 'custom']); - - $this->notifynder['category'] = 'custom'; - $this->notifynder['url'] = 'w'; - $this->notifynder['from'] = 1; - $this->notifynder['to'] = 1; - $notification = $this->notifynder->send(); - - $this->assertEquals('w', $notification->url); - } - - /** @test */ - public function it_send_using_notifynder_as_an_object() - { - $this->createCategory(['name' => 'custom']); - - $notifynder = $this->notifynder; - $notifynder->category = 'custom'; - $notifynder->url = 'w'; - $notifynder->from = 1; - $notifynder->to = 1; - $notification = $notifynder->send(); - - $this->assertEquals('w', $notification->url); - } - - /** - * @test - */ - public function it_store_extra_field_as_json() - { - $this->createCategory(['name' => 'custom']); - - $extra = ['extra.name' => 'amazing']; - - $notifications = $this->notifynder - ->category('custom') - ->extra($extra) - ->url('w') - ->from(1) - ->to(1); - - $notifications = $this->notifynder->send($notifications); - $this->assertEquals($notifications->extra->toArray(), $extra); - } - - /** - * It send multiple Notifications. - * - * @method send - * @group failing - * @test - */ - public function it_send_multiple_notifications() - { - Factory::times(10)->create(User::class); - $this->createCategory(['name' => 'me']); - - $allUsers = User::all(); - - $this->notifynder->loop($allUsers, function ($builder, $user) { - $builder->category('me') - ->url('you') - ->from(1) - ->to($user->id); - })->send(); - - // should send 10 notifications - $notifications = Notification::all(); - - $this->assertCount(10, $notifications); - } -} diff --git a/tests/integration/Repositories/GroupCategoryReposutoryTest.php b/tests/integration/Repositories/GroupCategoryReposutoryTest.php deleted file mode 100755 index 2a92bfa..0000000 --- a/tests/integration/Repositories/GroupCategoryReposutoryTest.php +++ /dev/null @@ -1,69 +0,0 @@ -categoryGroup = app('notifynder.group.category'); - } - - /** @test */ - public function it_add_a_category_to_a_group_id() - { - $category = $this->createCategory(); - $group = $this->createGroup(); - - $this->categoryGroup->addCategoryToGroupById( - $group->id, - $category->id - ); - - $this->assertEquals($group->categories[0]->name, $category->name); - } - - /** @test */ - public function it_add_a_category_to_a_group_by_name() - { - $category = $this->createCategory(); - $group = $this->createGroup(); - - $this->categoryGroup->addCategoryToGroupByName( - $group->name, - $category->name - ); - - $this->assertEquals($group->categories[0]->name, $category->name); - } - - /** @test */ - public function it_add_multiple_categories_to_a_group_by_name() - { - $category1 = $this->createCategory(); - $category2 = $this->createCategory(); - $group = $this->createGroup(); - - $this->categoryGroup->addMultipleCategoriesToGroup( - $group->name, - [$category1->name, $category2->name] - ); - - $this->assertCount(2, $group->categories); - } -} diff --git a/tests/integration/Repositories/GroupRepositoryTest.php b/tests/integration/Repositories/GroupRepositoryTest.php deleted file mode 100755 index d62b307..0000000 --- a/tests/integration/Repositories/GroupRepositoryTest.php +++ /dev/null @@ -1,67 +0,0 @@ -group = app('notifynder.group.repository'); - } - - /** @test */ - public function it_find_a_group_by_id() - { - $group = $this->createGroup(); - - $findGroup = $this->group->find($group->id); - - $this->assertEquals($group->id, $findGroup->id); - } - - /** @test */ - public function it_find_a_group_by_name() - { - $group_name = 'mygroup'; - $this->createGroup(['name' => $group_name]); - - $group = $this->group->findByName($group_name); - - $this->assertEquals($group_name, $group->name); - } - - /** @test */ - public function it_create_a_group() - { - $groupData = 'mygroup'; - - $group = $this->group->create($groupData); - - $this->assertEquals($groupData, $group->name); - } - - /** @test */ - public function it_delete_a_group_by_id() - { - $group = $this->createGroup(); - - $this->group->delete($group->id); - - $this->assertCount(0, NotificationGroup::all()); - } -} diff --git a/tests/integration/Repositories/NotificationCategoryDBTest.php b/tests/integration/Repositories/NotificationCategoryDBTest.php deleted file mode 100755 index 8510680..0000000 --- a/tests/integration/Repositories/NotificationCategoryDBTest.php +++ /dev/null @@ -1,96 +0,0 @@ -categoryRepo = app('notifynder.category.repository'); - } - - /** @test */ - public function it_find_a_category_by_id() - { - $record = $this->createCategory(); - - $category = $this->categoryRepo->find($record->id); - - $this->assertEquals(1, $category->id); - } - - /** @test */ - public function it_find_a_category_by_name() - { - $categoryName = 'test.category'; - - $this->createCategory(['name' => $categoryName]); - - $category = $this->categoryRepo->findByName($categoryName); - - $this->assertEquals($categoryName, $category->name); - } - - /** @test */ - public function it_find_categories_giving_multiple_names() - { - $categoryNames = ['test.first', 'test.second']; - - $this->createCategory(['name' => $categoryNames[0]]); - $this->createCategory(['name' => $categoryNames[1]]); - - $categories = $this->categoryRepo->findByNames($categoryNames); - - $this->assertCount(2, $categories); - } - - /** @test */ - public function it_add_a_new_category() - { - $categoryData = Factory::build('Fenos\Notifynder\Models\NotificationCategory'); - - $createCategory = $this->categoryRepo->add($categoryData->name, $categoryData->text); - - $this->assertEquals($categoryData->name, $createCategory->name); - } - - /** @test */ - public function it_delete_a_category_by_id() - { - $categoryToDelete = $this->createCategory(); - - $this->categoryRepo->delete($categoryToDelete->id); - - $tryToFindThatCategory = $this->categoryRepo->find($categoryToDelete->id); - - $this->assertEquals($tryToFindThatCategory, null); - } - - /** @test */ - public function it_delete_a_category_by_name() - { - $categoryToDelete = $this->createCategory(); - - $this->categoryRepo->deleteByName($categoryToDelete->name); - - $tryToFindThatCategory = $this->categoryRepo->findByName($categoryToDelete->name); - - $this->assertEquals($tryToFindThatCategory, null); - } -} diff --git a/tests/integration/Repositories/NotificationRepositoryDBTest.php b/tests/integration/Repositories/NotificationRepositoryDBTest.php deleted file mode 100755 index 316d894..0000000 --- a/tests/integration/Repositories/NotificationRepositoryDBTest.php +++ /dev/null @@ -1,282 +0,0 @@ - 1, - 'type' => 'User', - ]; - - /** - * @var int - */ - protected $multiNotificationsNumber = 10; - - /** - * @var int - */ - protected $to_id = 1; - - /** - * SetUp Tests. - */ - public function setUp() - { - parent::setUp(); - - $this->notificationRepo = app('notifynder.notification.repository'); - } - - /** @test */ - public function it_find_a_notification_by_id() - { - $notificationToSearch = $this->createNotification(); - - $notification = $this->notificationRepo->find($notificationToSearch->id); - - $this->assertEquals($notificationToSearch->id, $notification->id); - } - - /** @test */ - public function it_send_a_single_notification() - { - $notificationToSend = $this->buildNotification(); - - $notification = $this->notificationRepo->storeSingle($notificationToSend); - - $this->assertEquals($notificationToSend['to_id'], $notification->to_id); - $this->assertEquals($notificationToSend['to_type'], $notification->to_type); - } - - /** @test - * @group fails - */ - public function it_send_multiple_notification() - { - $notificationsToSend[0] = $this->buildNotification(); - $notificationsToSend[1] = $this->buildNotification(); - //dd($notificationsToSend); - $storeMultipleNotificaations = $this->notificationRepo->storeMultiple($notificationsToSend); - - $notifications = Notification::all(); - - $this->assertCount(2, $notifications); - $this->assertEquals(2, $storeMultipleNotificaations); - } - - /** @test */ - public function it_read_one_notification_by_id() - { - $notificationToRead = $this->createNotification(); - - $notificationRead = $this->notificationRepo->readOne($notificationToRead); - - $this->assertEquals(1, $notificationRead->read); - } - - /** @test */ - public function it_read_limit_the_number_of_notifications_of_the_given_entity() - { - $this->createMultipleNotifications(); - - $readFive = $this->notificationRepo->readLimit( - $this->to['id'], $this->to['type'], 5, 'asc' - ); - - $notificationsRead = Notification::whereRead(1)->get(); - - $this->assertEquals(5, $readFive); - $this->assertCount(5, $notificationsRead); - } - - /** @test */ - public function it_read_all_the_notifications_of_the_given_entity() - { - $this->createMultipleNotifications(); - - $notificationRead = $this->notificationRepo->readAll( - $this->to['id'], $this->to['type'] - ); - - $this->assertEquals(10, $notificationRead); - } - - /** @test */ - public function it_delete_a_notification_by_id() - { - $notificationToDelete = $this->createNotification(); - - $deleted = $this->notificationRepo->delete($notificationToDelete->id); - - $this->assertEquals(1, $deleted); - $this->assertCount(0, Notification::all()); - } - - /** @test */ - public function it_delete_all_the_notification_of_the_given_entity() - { - $this->createMultipleNotifications(); - - $deleted = $this->notificationRepo->deleteAll( - $this->to['id'], $this->to['type'] - ); - - $this->assertEquals(10, $deleted); - $this->assertCount(0, Notification::all()); - } - - /** @test */ - public function it_delete_notifications_limit_the_number_of_the_given_entity() - { - $this->createMultipleNotifications(); - - $notificationsDeleted = $this->notificationRepo->deleteLimit( - $this->to['id'], $this->to['type'], 5, 'asc' - ); - - $this->assertEquals(5, $notificationsDeleted); - $this->assertCount(5, Notification::all()); - } - - /** @test */ - public function it_count_notification_not_read() - { - $this->createMultipleNotifications(); - - $countNotRead = $this->notificationRepo->countNotRead( - $this->to['id'], $this->to['type'] - ); - - $this->assertEquals($this->multiNotificationsNumber, $countNotRead); - } - - /** @test */ - public function it_delete_all_notification_by_category() - { - $category = $this->createCategory(['name' => 'test']); - - $this->createNotification(['category_id' => $category->id]); - $this->createNotification(['category_id' => $category->id]); - $this->createNotification(); - - $this->notificationRepo->deleteByCategory($category->name); - - $this->assertCount(1, Notification::all()); - } - - /** @test */ - public function it_delete_all_notification_expired_by_category_name() - { - $category = $this->createCategory(['name' => 'test']); - - $this->createNotification([ - 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->subDays(1), - ]); - - $this->createNotification([ - 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->subDays(1), - ]); - - $this->createNotification([ - 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->subDays(1), - ]); - - $this->createNotification([ - 'category_id' => $category->id, - 'expire_time' => Carbon\Carbon::now()->addDays(1), - ]); - - $this->notificationRepo->deleteByCategory($category->name, true); - - $this->assertCount(1, Notification::all()); - } - - /** @test */ - public function it_get_the_last_notificiation_sent() - { - $category = $this->createCategory(['name' => 'test']); - - $this->createNotification([ - 'category_id' => $category->id, - 'url' => 'first', - 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(1), - ]); - - $this->createNotification([ - 'category_id' => $category->id, - 'url' => 'second', - 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(2), - ]); - - $notification = $this->notificationRepo->getLastNotification(1, null); - - $this->assertEquals('second', $notification->url); - } - - /** @test */ - public function it_get_the_last_notificiation_sent_by_category() - { - $category1 = $this->createCategory(['name' => 'test']); - $category2 = $this->createCategory(['name' => 'test2']); - - $this->createNotification([ - 'category_id' => $category1->id, - 'url' => 'first', - 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(1), - ]); - - $this->createNotification([ - 'category_id' => $category1->id, - 'url' => 'second', - 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(2), - ]); - - $this->createNotification([ - 'category_id' => $category2->id, - 'url' => 'third', - 'to_id' => 1, - 'created_at' => Carbon\Carbon::now()->addDay(3), - ]); - - $notificationByName = $this->notificationRepo->getLastNotificationByCategory('test', 1, null); - $notificationById = $this->notificationRepo->getLastNotificationByCategory($category1->id, 1, null); - - $this->assertEquals('second', $notificationByName->url); - $this->assertEquals('second', $notificationById->url); - } - - /** - * Shortcut to build a new notification. - * - * @param array $data - * @return array - */ - protected function buildNotification(array $data = []) - { - $notification = Factory::build(Notification::class, $data)->toArray(); - $notification['extra'] = json_encode($notification['extra']); - - return $notification; - } -} diff --git a/tests/integration/Senders/SendersTest.php b/tests/integration/Senders/SendersTest.php deleted file mode 100755 index d21fa86..0000000 --- a/tests/integration/Senders/SendersTest.php +++ /dev/null @@ -1,175 +0,0 @@ -set( - 'notifynder.notification_model', - 'Fenos\Notifynder\Models\Notification' - ); - - $this->senders = app('notifynder.sender'); - $this->builder = app('notifynder.builder'); - $this->group = app('notifynder.group'); - } - - /** @test */ - public function it_send_now_a_single_notification() - { - $category_name = 'my.category'; - $this->createCategory(['name' => $category_name]); - - $singleNotification = $this->builder->category($category_name) - ->to(1) - ->from(2) - ->url('www.notifynder.io') - ->toArray(); - - // Send Single - $this->senders->sendNow($singleNotification); - - $stackIds = Notification::lists('stack_id'); - if ($stackIds instanceof \Illuminate\Support\Collection) { - $stackIds = $stackIds->toArray(); - } - $stackIds = array_unique($stackIds); - - $this->assertCount(1, Notification::all()); - $this->assertCount(1, $stackIds); - $this->assertEquals([null], $stackIds); - } - - /** @test */ - public function it_send_now_a_mutiple_notification() - { - $category_name = 'my.category'; - $this->createCategory(['name' => $category_name]); - - $user_ids = [1, 2]; - - $sendMultiple = $this->builder->loop($user_ids, - function (NotifynderBuilder $builder, $value) use ($category_name) { - return $builder->category($category_name) - ->to($value) - ->from(2) - ->url('www.notifynder.io') - ->toArray(); - }); - - // Send Single - $this->senders->sendNow($sendMultiple); - - $stackIds = Notification::lists('stack_id'); - if ($stackIds instanceof \Illuminate\Support\Collection) { - $stackIds = $stackIds->toArray(); - } - $stackIds = array_unique($stackIds); - - $this->assertCount(2, Notification::all()); - $this->assertCount(1, $stackIds); - $this->assertEquals([1], $stackIds); - } - - /** @test */ - public function it_send_a_group_of_notification() - { - $group = $this->createGroup(['name' => 'mygroud']); - $category1 = $this->createCategory(); - $category2 = $this->createCategory(); - $category3 = $this->createCategory(); - - $this->group->addMultipleCategoriesToGroup($group->name, - $category1->name, - $category2->name, - $category3->name - ); - - $this->senders->sendGroup($group->name, [ - 'from_id' => 1, - 'to_id' => 2, - 'url' => 'www.notifynder.io', - ]); - - $this->assertCount(3, Notification::all()); - } - - /** @test */ - public function it_send_with_an_custom_sender() - { - $this->senders->extend('sendCustom', function ($notification, $app) { - return new CustomDefaultSender($notification, $app->make('notifynder')); - }); - - $category_name = 'my.category'; - $this->createCategory(['name' => $category_name]); - - $singleNotification = $this->builder->category($category_name) - ->to(1) - ->from(2) - ->url('www.notifynder.io') - ->toArray(); - - $this->senders->sendCustom($singleNotification); - - $this->assertCount(1, Notification::all()); - } - - /** @test */ - public function it_send_multiple_with_an_custom_sender() - { - $this->senders->extend('sendCustom', function ($notification, $app) { - return new CustomDefaultSender($notification, $app->make('notifynder')); - }); - - $category_name = 'my.category'; - $this->createCategory(['name' => $category_name]); - - $multipleNotifications = []; - $multipleNotifications[] = $this->builder->category($category_name) - ->to(1) - ->from(2) - ->url('www.notifynder.io') - ->toArray(); - $multipleNotifications[] = $this->builder->category($category_name) - ->to(2) - ->from(1) - ->url('notifynder.com') - ->toArray(); - - $this->senders->sendCustom($multipleNotifications); - - $this->assertCount(2, Notification::all()); - } -} diff --git a/tests/integration/Translator/TranslatorTest.php b/tests/integration/Translator/TranslatorTest.php deleted file mode 100755 index 5a10eca..0000000 --- a/tests/integration/Translator/TranslatorTest.php +++ /dev/null @@ -1,37 +0,0 @@ -set('notifynder.translations', $translations); - $this->translator = app('notifynder.translator'); - } - - /** @test */ - public function it_translate_a_notification() - { - $translation = $this->translator->translate('it', 'welcome'); - - $this->assertEquals('benvenuto', $translation); - } -} diff --git a/tests/integration/Translator/translations.php b/tests/integration/Translator/translations.php deleted file mode 100755 index 701def0..0000000 --- a/tests/integration/Translator/translations.php +++ /dev/null @@ -1,9 +0,0 @@ - [ - 'welcome' => 'benvenuto', - ], - -]; diff --git a/tests/migrations/2014_08_01_164248_create_users_table.php b/tests/migrations/2014_08_01_164248_create_users_table.php deleted file mode 100755 index 58e6bd1..0000000 --- a/tests/migrations/2014_08_01_164248_create_users_table.php +++ /dev/null @@ -1,32 +0,0 @@ -increments('id'); - $table->string('name'); - $table->string('surname'); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('users'); - } -} diff --git a/tests/models/User.php b/tests/models/User.php deleted file mode 100755 index 9957d47..0000000 --- a/tests/models/User.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Fri, 17 Jun 2016 10:20:18 -0400 Subject: [PATCH 109/210] Applied fixes from StyleCI --- src/Notifynder/Collections/Config.php | 7 ++++--- src/Notifynder/Contracts/ConfigContract.php | 2 +- src/Notifynder/Helpers/helpers.php | 6 +++--- src/Notifynder/Managers/NotifynderManager.php | 10 ---------- src/Notifynder/Models/Notification.php | 8 ++------ src/Notifynder/Models/NotificationCategory.php | 1 + src/Notifynder/Traits/Notifable.php | 2 ++ 7 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index a8f9308..c8d9c3c 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -23,16 +23,17 @@ public function isPolymorphic() public function getNotificationModel() { $class = $this->get('notification_model'); - if(class_exists($class)) { + if (class_exists($class)) { return $class; } + return Notification::class; } public function getNotifiedModel() { $class = $this->get('model'); - if(class_exists($class)) { + if (class_exists($class)) { return $class; } throw new \InvalidArgumentException("The model class [{$class}] doesn't exist."); @@ -67,4 +68,4 @@ public function __set($key, $value) { $this->set($key, $value); } -} \ No newline at end of file +} diff --git a/src/Notifynder/Contracts/ConfigContract.php b/src/Notifynder/Contracts/ConfigContract.php index db0675b..87533c5 100644 --- a/src/Notifynder/Contracts/ConfigContract.php +++ b/src/Notifynder/Contracts/ConfigContract.php @@ -21,4 +21,4 @@ public function set($key, $value); public function __get($key); public function __set($key, $value); -} \ No newline at end of file +} diff --git a/src/Notifynder/Helpers/helpers.php b/src/Notifynder/Helpers/helpers.php index a459d65..72084d6 100644 --- a/src/Notifynder/Helpers/helpers.php +++ b/src/Notifynder/Helpers/helpers.php @@ -1,6 +1,6 @@ get($key, $default); } -} \ No newline at end of file +} diff --git a/src/Notifynder/Managers/NotifynderManager.php b/src/Notifynder/Managers/NotifynderManager.php index 549ec21..499cfd3 100755 --- a/src/Notifynder/Managers/NotifynderManager.php +++ b/src/Notifynder/Managers/NotifynderManager.php @@ -2,18 +2,8 @@ namespace Fenos\Notifynder\Managers; -use BadMethodCallException; -use Closure; -use Fenos\Notifynder\Builder\NotifynderBuilder; -use Fenos\Notifynder\Contracts\NotifynderCategory; use Fenos\Notifynder\Contracts\NotifynderContract; -use Fenos\Notifynder\Contracts\NotifynderDispatcher; -use Fenos\Notifynder\Contracts\NotifynderGroup; -use Fenos\Notifynder\Contracts\NotifynderNotification; -use Fenos\Notifynder\Contracts\NotifynderSender; -use InvalidArgumentException; class NotifynderManager implements NotifynderContract { - } diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 3c19e41..25f8fb0 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -2,13 +2,7 @@ namespace Fenos\Notifynder\Models; -use Fenos\Notifynder\Notifications\ExtraParams; -use Fenos\Notifynder\Parsers\NotifynderParser; -use Illuminate\Contracts\Container\Container; -use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; -use Carbon\Carbon; -use Illuminate\Support\Arr; class Notification extends Model { @@ -42,6 +36,7 @@ public function from() if (notifynder_config()->isPolymorphic()) { return $this->belongsTo(notifynder_config()->getModel(), 'from_id'); } + return $this->morphTo(); } @@ -50,6 +45,7 @@ public function to() if (notifynder_config()->isPolymorphic()) { return $this->belongsTo(notifynder_config()->getModel(), 'to_id'); } + return $this->morphTo(); } diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 1d37ab0..f050369 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -16,6 +16,7 @@ public function notifications() { $config = app('notifynder.config'); $model = $config->getNotificationModel(); + return $this->hasMany($model, 'category_id'); } diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 477cd14..67c87a9 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -1,4 +1,5 @@ isPolymorphic()) { return $this->morphMany($model, 'to'); } + return $this->hasMany($model, 'to_id'); } } From cb4e5e15189edc58958f3ea4694d9cdce66fa834 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 17 Jun 2016 16:20:45 +0200 Subject: [PATCH 110/210] add author to composer json --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 38cf645..8554819 100755 --- a/composer.json +++ b/composer.json @@ -8,6 +8,11 @@ "name": "Fabrizio Fenoglio", "email": "fabri_feno@yahoo.it", "role": "Developer" + }, + { + "name": "Tom Witkowski", + "email": "dev.gummibeer@gmail.com", + "role": "Developer" } ], "require": { From 501c453fa9260a32faa564aa787a6eb2a0cbc648 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 17 Jun 2016 16:51:46 +0200 Subject: [PATCH 111/210] add Notification "Model" for not stored Notifications (notifications in progress) --- src/Notifynder/Builder/Notification.php | 64 +++++++++++++++++++++++++ src/Notifynder/Models/Notification.php | 4 ++ 2 files changed, 68 insertions(+) create mode 100644 src/Notifynder/Builder/Notification.php diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php new file mode 100644 index 0000000..ff51d84 --- /dev/null +++ b/src/Notifynder/Builder/Notification.php @@ -0,0 +1,64 @@ +attributes; + } + + public function attribute($key, $default = null) + { + return $this->get($key, $default); + } + + public function get($key, $default = null) + { + return Arr::get($this->attributes, $key, $default); + } + + public function set($key, $value) + { + Arr::set($this->attributes, $key, $value); + } + + public function __get($key) + { + return $this->get($key); + } + + public function __set($key, $value) + { + $this->set($key, $value); + } + + public function toJson($options = 0) + { + return json_encode($this->jsonSerialize(), $options); + } + + public function jsonSerialize() + { + return $this->toArray(); + } + + public function toArray() + { + return array_map(function ($value) { + return $value instanceof Arrayable ? $value->toArray() : $value; + }, $this->attributes); + } + + public function __toString() + { + return $this->toJson(); + } +} \ No newline at end of file diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 25f8fb0..e636f4d 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -19,6 +19,10 @@ class Notification extends Model 'stack_id', ]; + protected $casts = [ + 'extra' => 'array', + ]; + public function __construct(array $attributes = []) { $this->fillable($this->mergeFillables()); From 88c70f0312ba9fa6a149d6b86e6854ed8e89b5ca Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 17 Jun 2016 10:51:53 -0400 Subject: [PATCH 112/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Notification.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index ff51d84..9db826d 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -1,4 +1,5 @@ toJson(); } -} \ No newline at end of file +} From 5d94987eaae1e24d852af2f49811bc4fb7547ce4 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 17 Jun 2016 17:38:15 +0200 Subject: [PATCH 113/210] add the Builder and make it much cleaner add a TypeChecker as helper --- src/Notifynder/Builder/Builder.php | 140 ++++++++++++++++++ src/Notifynder/Helpers/TypeChecker.php | 56 +++++++ src/Notifynder/Models/Notification.php | 2 +- .../Models/NotificationCategory.php | 6 + 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100755 src/Notifynder/Builder/Builder.php create mode 100644 src/Notifynder/Helpers/TypeChecker.php diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php new file mode 100755 index 0000000..4d12e13 --- /dev/null +++ b/src/Notifynder/Builder/Builder.php @@ -0,0 +1,140 @@ +notification = new Notification(); + $this->typeChecker = new TypeChecker(); + } + + public function category($category) + { + $categoryId = $category; + if (! is_numeric($category)) { + $categoryId = NotificationCategory::byName($category)->findOrFail()->getKey(); + } elseif($category instanceof NotificationCategory) { + $categoryId = $category->getKey(); + } + + $this->setNotificationData('category_id', $categoryId); + + return $this; + } + + public function from() + { + $args = func_get_args(); + $this->setEntityData($args, 'from'); + return $this; + } + + public function to() + { + $args = func_get_args(); + $this->setEntityData($args, 'to'); + return $this; + } + + public function url($url) + { + $this->typeChecker->isString($url); + $this->setNotificationData('url', $url); + return $this; + } + + public function expire($datetime) + { + $this->typeChecker->isDate($datetime); + $this->setNotificationData('expire_time', $datetime); + return $this; + } + + public function extra(array $extra = []) + { + $this->typeChecker->isArray($extra); + $this->setNotificationData('extra', $extra); + return $this; + } + + public function setDates() + { + $date = Carbon::now(); + + $this->setNotificationData('updated_at', $date); + $this->setNotificationData('created_at', $date); + } + + protected function setEntityData($entity, $property) + { + if (is_array($entity) && count($entity) == 2) { + $this->typeChecker->isString($entity[0]); + $this->typeChecker->isNumeric($entity[1]); + + $type = $entity[0]; + $id = $entity[1]; + } elseif ($entity[0] instanceof Model) { + $type = $entity[0]->getMorphClass(); + $id = $entity[0]->getKey(); + } else { + $this->typeChecker->isNumeric($entity[0]); + + $type = notifynder_config()->getNotifiedModel(); + $id = $entity[0]; + } + + $this->setNotificationData("{$property}_type", $type); + $this->setNotificationData("{$property}_id", $id); + } + + protected function setNotificationData($key, $value) + { + $this->notification->set($key, $value); + } + + public function getNotification() + { + $this->setDates(); + return $this->notification; + } + + public function addNotification(Notification $notification) + { + $this->notifications[] = $notification; + } + + public function getNotifications() + { + if(count($this->notifications) == 0) { + $this->addNotification($this->getNotification()); + } + return $this->notifications; + } + + public function loop($data, Closure $callback) + { + $this->typeChecker->isIterable($data); + + foreach ($data as $key => $value) { + $builder = new static(); + $callback($builder, $value, $key); + $this->addNotification($builder->getNotification()); + } + + return $this; + } +} diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php new file mode 100644 index 0000000..4de4092 --- /dev/null +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -0,0 +1,56 @@ + 0) { + return true; + } + + throw new InvalidArgumentException('The value passed must be an array'); + } + + public function isIterable($value) + { + if((is_array($value) || $value instanceof Traversable) && count($value) > 0) { + return true; + } + + throw new InvalidArgumentException('The value passed must be iterable'); + } +} \ No newline at end of file diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index e636f4d..1cd3d01 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -15,7 +15,7 @@ class Notification extends Model 'read', 'url', 'extra', - 'expire_time', + 'expire_time', // ToDo: rename to `expires_at` 'stack_id', ]; diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index f050369..13f13db 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -2,6 +2,7 @@ namespace Fenos\Notifynder\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class NotificationCategory extends Model @@ -29,4 +30,9 @@ public function categories() 'group_id' ); } + + public function scopeByName(Builder $query, $name) + { + return $query->where('name', $name); + } } From 1f44958c155df52cb69cc3922a2686dddc36af15 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 17 Jun 2016 11:38:28 -0400 Subject: [PATCH 114/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Builder.php | 11 +++++++++-- src/Notifynder/Helpers/TypeChecker.php | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 4d12e13..6df6233 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -27,7 +27,7 @@ public function category($category) $categoryId = $category; if (! is_numeric($category)) { $categoryId = NotificationCategory::byName($category)->findOrFail()->getKey(); - } elseif($category instanceof NotificationCategory) { + } elseif ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); } @@ -40,6 +40,7 @@ public function from() { $args = func_get_args(); $this->setEntityData($args, 'from'); + return $this; } @@ -47,6 +48,7 @@ public function to() { $args = func_get_args(); $this->setEntityData($args, 'to'); + return $this; } @@ -54,6 +56,7 @@ public function url($url) { $this->typeChecker->isString($url); $this->setNotificationData('url', $url); + return $this; } @@ -61,6 +64,7 @@ public function expire($datetime) { $this->typeChecker->isDate($datetime); $this->setNotificationData('expire_time', $datetime); + return $this; } @@ -68,6 +72,7 @@ public function extra(array $extra = []) { $this->typeChecker->isArray($extra); $this->setNotificationData('extra', $extra); + return $this; } @@ -109,6 +114,7 @@ protected function setNotificationData($key, $value) public function getNotification() { $this->setDates(); + return $this->notification; } @@ -119,9 +125,10 @@ public function addNotification(Notification $notification) public function getNotifications() { - if(count($this->notifications) == 0) { + if (count($this->notifications) == 0) { $this->addNotification($this->getNotification()); } + return $this->notifications; } diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index 4de4092..a7be1d7 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -47,10 +47,10 @@ public function isArray($value) public function isIterable($value) { - if((is_array($value) || $value instanceof Traversable) && count($value) > 0) { + if ((is_array($value) || $value instanceof Traversable) && count($value) > 0) { return true; } throw new InvalidArgumentException('The value passed must be iterable'); } -} \ No newline at end of file +} From e7ecec53d2949a3ba7cfeeec25f589b23c4eaaf7 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 20 Jun 2016 11:03:27 +0200 Subject: [PATCH 115/210] add notification validation --- src/Notifynder/Builder/Builder.php | 5 ++++ src/Notifynder/Builder/Notification.php | 27 +++++++++++++++++++ src/Notifynder/Collections/Config.php | 5 ++++ src/Notifynder/Contracts/ConfigContract.php | 2 ++ .../UnvalidNotificationException.php | 22 +++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 src/Notifynder/Exceptions/UnvalidNotificationException.php diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 6df6233..160f573 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -4,6 +4,7 @@ use Closure; use Carbon\Carbon; +use Fenos\Notifynder\Exceptions\UnvalidNotificationException; use Fenos\Notifynder\Helpers\TypeChecker; use Fenos\Notifynder\Models\NotificationCategory; use Illuminate\Database\Eloquent\Model; @@ -113,6 +114,10 @@ protected function setNotificationData($key, $value) public function getNotification() { + if(!$this->notification->isValid()) { + throw new UnvalidNotificationException($this->notification); + } + $this->setDates(); return $this->notification; diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index 9db826d..a98eb03 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -11,6 +11,18 @@ class Notification implements Arrayable, Jsonable, JsonSerializable { protected $attributes = []; + protected $requiredFields = [ + 'from_id', + 'to_id', + 'category_id', + ]; + + public function __construct() + { + $customRequired = notifynder_config()->getAdditionalRequiredFields(); + $this->requiredFields = array_merge($this->requiredFields, $customRequired); + } + public function attributes() { return $this->attributes; @@ -21,6 +33,11 @@ public function attribute($key, $default = null) return $this->get($key, $default); } + public function has($key) + { + return Arr::has($this->attributes, $key); + } + public function get($key, $default = null) { return Arr::get($this->attributes, $key, $default); @@ -31,6 +48,16 @@ public function set($key, $value) Arr::set($this->attributes, $key, $value); } + public function isValid() + { + foreach ($this->requiredFields as $field) { + if (!$this->has($field)) { + return false; + } + } + return true; + } + public function __get($key) { return $this->get($key); diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index c8d9c3c..99e75a3 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -44,6 +44,11 @@ public function getAdditionalFields() return Arr::flatten($this->get('additional_fields', [])); } + public function getAdditionalRequiredFields() + { + return Arr::flatten($this->get('additional_fields.required', [])); + } + public function get($key, $default = null) { return Arr::get($this->items, $key, $default); diff --git a/src/Notifynder/Contracts/ConfigContract.php b/src/Notifynder/Contracts/ConfigContract.php index 87533c5..12cda40 100644 --- a/src/Notifynder/Contracts/ConfigContract.php +++ b/src/Notifynder/Contracts/ConfigContract.php @@ -11,6 +11,8 @@ public function getNotificationModel(); public function getNotifiedModel(); public function getAdditionalFields(); + + public function getAdditionalRequiredFields(); public function get($key, $default); diff --git a/src/Notifynder/Exceptions/UnvalidNotificationException.php b/src/Notifynder/Exceptions/UnvalidNotificationException.php new file mode 100644 index 0000000..cddc730 --- /dev/null +++ b/src/Notifynder/Exceptions/UnvalidNotificationException.php @@ -0,0 +1,22 @@ +notification = $notification; + } + + public function getNotification() + { + return $this->notification; + } +} \ No newline at end of file From bf84aa95f4f3b863a6b326086fde99d18387398a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 20 Jun 2016 05:03:53 -0400 Subject: [PATCH 116/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Builder.php | 2 +- src/Notifynder/Builder/Notification.php | 3 ++- src/Notifynder/Contracts/ConfigContract.php | 2 +- src/Notifynder/Exceptions/UnvalidNotificationException.php | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 160f573..cdf3a98 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -114,7 +114,7 @@ protected function setNotificationData($key, $value) public function getNotification() { - if(!$this->notification->isValid()) { + if (! $this->notification->isValid()) { throw new UnvalidNotificationException($this->notification); } diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index a98eb03..d1809c8 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -51,10 +51,11 @@ public function set($key, $value) public function isValid() { foreach ($this->requiredFields as $field) { - if (!$this->has($field)) { + if (! $this->has($field)) { return false; } } + return true; } diff --git a/src/Notifynder/Contracts/ConfigContract.php b/src/Notifynder/Contracts/ConfigContract.php index 12cda40..8337f77 100644 --- a/src/Notifynder/Contracts/ConfigContract.php +++ b/src/Notifynder/Contracts/ConfigContract.php @@ -11,7 +11,7 @@ public function getNotificationModel(); public function getNotifiedModel(); public function getAdditionalFields(); - + public function getAdditionalRequiredFields(); public function get($key, $default); diff --git a/src/Notifynder/Exceptions/UnvalidNotificationException.php b/src/Notifynder/Exceptions/UnvalidNotificationException.php index cddc730..33a067a 100644 --- a/src/Notifynder/Exceptions/UnvalidNotificationException.php +++ b/src/Notifynder/Exceptions/UnvalidNotificationException.php @@ -1,4 +1,5 @@ notification; } -} \ No newline at end of file +} From 41b31b4683c0fa6106c83763af01efa1cb9095f7 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 20 Jun 2016 15:48:39 +0200 Subject: [PATCH 117/210] add unittests for builder --- composer.json | 5 +- src/Notifynder/Builder/Notification.php | 2 +- tests/NotifynderTestCase.php | 51 ++++++++++ tests/integration/Builder/BuilderTest.php | 115 ++++++++++++++++++++++ tests/models/User.php | 12 +++ 5 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 tests/NotifynderTestCase.php create mode 100644 tests/integration/Builder/BuilderTest.php create mode 100644 tests/models/User.php diff --git a/composer.json b/composer.json index 8554819..b75d4e4 100755 --- a/composer.json +++ b/composer.json @@ -35,12 +35,13 @@ "Fenos\\Notifynder\\": "src/Notifynder" }, "files": [ - "app/Helpers/helpers.php" + + "src/Notifynder/Helpers/helpers.php" ] }, "autoload-dev": { "classmap": [ - "tests/TestCaseDB.php" + "tests/NotifynderTestCase.php" ], "psr-4": { "Fenos\\Tests\\": "tests/models" diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index a98eb03..50bafbe 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -82,7 +82,7 @@ public function toArray() { return array_map(function ($value) { return $value instanceof Arrayable ? $value->toArray() : $value; - }, $this->attributes); + }, $this->attributes()); } public function __toString() diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php new file mode 100644 index 0000000..175ee85 --- /dev/null +++ b/tests/NotifynderTestCase.php @@ -0,0 +1,51 @@ +app->make('Illuminate\Contracts\Console\Kernel'); + app('db')->beginTransaction(); + $this->migrate($artisan); + // Set up the User Test Model + app('config')->set('notifynder.notification_model', 'Fenos\Notifynder\Models\Notification'); + app('config')->set('notifynder.model', 'Fenos\Tests\Models\User'); + } + + protected function getEnvironmentSetUp($app) + { + $app['config']->set('database.default', 'testbench'); + $app['config']->set('database.connections.testbench', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + } + + public function tearDown() + { + app('db')->rollback(); + } + + protected function getApplicationTimezone($app) + { + return 'UTC'; + } + + private function migrate($artisan, $path = '/../../../../src/migrations') + { + $artisan->call('migrate', [ + '--database' => 'testbench', + '--path' => $path, + ]); + } +} \ No newline at end of file diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php new file mode 100644 index 0000000..222f13d --- /dev/null +++ b/tests/integration/Builder/BuilderTest.php @@ -0,0 +1,115 @@ +category(1) + ->from(1) + ->to(2) + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + + $this->assertSame(1, $notification->category_id); + $this->assertSame(1, $notification->from_id); + $this->assertSame('Fenos\Tests\Models\User', $notification->from_type); + $this->assertSame(2, $notification->to_id); + $this->assertSame('Fenos\Tests\Models\User', $notification->to_type); + $this->assertInstanceOf(Carbon::class, $notification->created_at); + $this->assertInstanceOf(Carbon::class, $notification->updated_at); + } + + public function testCreateSingleNotificationWithAll() + { + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(1) + ->to(2) + ->url('https://google.com') + ->extra([ + 'foo' => 'bar', + ]) + ->expire(Carbon::tomorrow()) + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + + $this->assertSame('https://google.com', $notification->url); + $this->assertInternalType('array', $notification->extra); + $this->assertCount(1, $notification->extra); + $this->assertSame('bar', $notification->extra['foo']); + $this->assertInstanceOf(Carbon::class, $notification->expire_time); + } + + public function testCreateSingleNotificationAndGetArray() + { + $builder = new Builder(); + $notifications = $builder + ->category(1) + ->from(1) + ->to(2) + ->getNotifications(); + + $this->assertInternalType('array', $notifications); + $this->assertCount(1, $notifications); + + $this->assertInstanceOf(Notification::class, $notifications[0]); + } + + public function testCreateSingleUnvalidNotification() + { + $this->setExpectedException(UnvalidNotificationException::class); + + $builder = new Builder(); + $builder + ->from(1) + ->to(2) + ->getNotification(); + } + + public function testCreateMultipleNotifications() + { + $datas = [2,3,4]; + $builder = new Builder(); + $notifications = $builder->loop($datas, function($builder, $data) { + $builder->category(1) + ->from(1) + ->to($data); + })->getNotifications(); + + $this->assertInternalType('array', $notifications); + $this->assertCount(count($datas), $notifications); + + foreach($notifications as $index => $notification) { + $this->assertInstanceOf(Notification::class, $notification); + + $this->assertSame(1, $notification->category_id); + $this->assertSame(1, $notification->from_id); + $this->assertSame('Fenos\Tests\Models\User', $notification->from_type); + $this->assertSame($datas[$index], $notification->to_id); + $this->assertSame('Fenos\Tests\Models\User', $notification->to_type); + $this->assertInstanceOf(Carbon::class, $notification->created_at); + $this->assertInstanceOf(Carbon::class, $notification->updated_at); + } + } + + public function testCreateMultipleUnvalidNotifications() + { + $this->setExpectedException(UnvalidNotificationException::class); + + $builder = new Builder(); + $builder->loop([2,3,4], function($builder, $data) { + $builder->category(1) + ->to($data); + })->getNotifications(); + } +} \ No newline at end of file diff --git a/tests/models/User.php b/tests/models/User.php new file mode 100644 index 0000000..68e4d31 --- /dev/null +++ b/tests/models/User.php @@ -0,0 +1,12 @@ + Date: Mon, 20 Jun 2016 09:48:51 -0400 Subject: [PATCH 118/210] Applied fixes from StyleCI --- tests/NotifynderTestCase.php | 2 +- tests/integration/Builder/BuilderTest.php | 10 +++++----- tests/models/User.php | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index 175ee85..8eeba49 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -48,4 +48,4 @@ private function migrate($artisan, $path = '/../../../../src/migrations') '--path' => $path, ]); } -} \ No newline at end of file +} diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php index 222f13d..86eb4c3 100644 --- a/tests/integration/Builder/BuilderTest.php +++ b/tests/integration/Builder/BuilderTest.php @@ -78,9 +78,9 @@ public function testCreateSingleUnvalidNotification() public function testCreateMultipleNotifications() { - $datas = [2,3,4]; + $datas = [2, 3, 4]; $builder = new Builder(); - $notifications = $builder->loop($datas, function($builder, $data) { + $notifications = $builder->loop($datas, function ($builder, $data) { $builder->category(1) ->from(1) ->to($data); @@ -89,7 +89,7 @@ public function testCreateMultipleNotifications() $this->assertInternalType('array', $notifications); $this->assertCount(count($datas), $notifications); - foreach($notifications as $index => $notification) { + foreach ($notifications as $index => $notification) { $this->assertInstanceOf(Notification::class, $notification); $this->assertSame(1, $notification->category_id); @@ -107,9 +107,9 @@ public function testCreateMultipleUnvalidNotifications() $this->setExpectedException(UnvalidNotificationException::class); $builder = new Builder(); - $builder->loop([2,3,4], function($builder, $data) { + $builder->loop([2, 3, 4], function ($builder, $data) { $builder->category(1) ->to($data); })->getNotifications(); } -} \ No newline at end of file +} diff --git a/tests/models/User.php b/tests/models/User.php index 68e4d31..c2bbcb0 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -1,4 +1,5 @@ Date: Mon, 20 Jun 2016 17:42:20 +0200 Subject: [PATCH 119/210] add sendermanager including the two basic senders --- src/Notifynder/Builder/Builder.php | 6 +- .../Contracts/NotifynderContract.php | 72 ---------------- .../Contracts/NotifynderManagerContract.php | 16 ++++ src/Notifynder/Contracts/SenderContract.php | 9 ++ .../Contracts/SenderManagerContract.php | 17 ++++ src/Notifynder/Managers/NotifynderManager.php | 84 ++++++++++++++++++- src/Notifynder/Managers/SenderManager.php | 59 +++++++++++++ src/Notifynder/Models/Notification.php | 7 +- src/Notifynder/NotifynderServiceProvider.php | 39 +++++++-- src/Notifynder/Senders/MultipleSender.php | 39 +++++++++ src/Notifynder/Senders/SingleSender.php | 22 +++++ .../Managers/NotifynderManagerTest.php | 81 ++++++++++++++++++ 12 files changed, 366 insertions(+), 85 deletions(-) delete mode 100755 src/Notifynder/Contracts/NotifynderContract.php create mode 100755 src/Notifynder/Contracts/NotifynderManagerContract.php create mode 100644 src/Notifynder/Contracts/SenderContract.php create mode 100644 src/Notifynder/Contracts/SenderManagerContract.php create mode 100644 src/Notifynder/Managers/SenderManager.php create mode 100644 src/Notifynder/Senders/MultipleSender.php create mode 100644 src/Notifynder/Senders/SingleSender.php create mode 100644 tests/integration/Managers/NotifynderManagerTest.php diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index cdf3a98..9058e59 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -26,10 +26,10 @@ public function __construct() public function category($category) { $categoryId = $category; - if (! is_numeric($category)) { - $categoryId = NotificationCategory::byName($category)->findOrFail()->getKey(); - } elseif ($category instanceof NotificationCategory) { + if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); + } elseif (!is_numeric($category)) { + $categoryId = NotificationCategory::byName($category)->findOrFail()->getKey(); } $this->setNotificationData('category_id', $categoryId); diff --git a/src/Notifynder/Contracts/NotifynderContract.php b/src/Notifynder/Contracts/NotifynderContract.php deleted file mode 100755 index 705a415..0000000 --- a/src/Notifynder/Contracts/NotifynderContract.php +++ /dev/null @@ -1,72 +0,0 @@ -sender = $sender; + } + + public function category($category) + { + $this->builder(true); + $this->builder->category($category); + return $this; + } + + public function loop($data, Closure $callback) + { + $this->builder(true); + $this->builder->loop($data, $callback); + return $this; + } + + public function builder($new = false) + { + if(is_null($this->builder) || $new) { + $this->builder = new Builder(); + } + return $this->builder; + } + + public function send() + { + $sent = $this->sender->send($this->builder->getNotifications()); + $this->reset(); + return $sent; + } + + public function sender() + { + return $this->sender; + } + + protected function reset() + { + $this->builder = null; + } + + public function extend($name, Closure $sender) + { + return $this->sender->extend($name, $sender); + } + + public function __call($name, $arguments) + { + if (Str::startsWith($name, 'send')) { + $sent = $this->sender->sendWithCustomSender($name, $this->builder->getNotifications()); + $this->reset(); + return $sent; + } + + if($this->builder instanceof Builder && method_exists($this->builder, $name)) { + $result = call_user_func_array([$this->builder, $name], $arguments); + if(Str::startsWith($name, 'get')) { + return $result; + } + return $this; + } + + $error = "The method [$name] doesn't exist in the class ".self::class; + throw new BadMethodCallException($error); + } } diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php new file mode 100644 index 0000000..de7204d --- /dev/null +++ b/src/Notifynder/Managers/SenderManager.php @@ -0,0 +1,59 @@ +sendSingle($notifications); + } + return $this->sendMultiple($notifications); + } + + public function hasSender($name) + { + return Arr::has($this->senders, $name); + } + + public function getSender($name) + { + return Arr::get($this->senders, $name); + } + + public function extend($name, Closure $sender) + { + $this->senders[$name] = $sender; + return true; + } + + public function sendWithCustomSender($name, array $notifications) + { + if($this->hasSender($name)) { + $sender = call_user_func_array($this->getSender($name), [$notifications]); + if($sender instanceof SenderContract) { + return (bool) $sender->send($this); + } + throw new BadFunctionCallException("The sender [{$name}] hasn't returned an instance of ".SenderContract::class); + } + throw new BadMethodCallException("The sender [{$name}] isn't registered."); + } + + public function __call($name, $arguments) + { + if (isset($arguments[0]) && is_array($arguments[0])) { + return $this->sendWithCustomSender($name, $arguments[0]); + } + + throw new BadMethodCallException('No argument passed to the custom sender, please provide notifications array'); + } +} \ No newline at end of file diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 1cd3d01..6b90d35 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -2,6 +2,7 @@ namespace Fenos\Notifynder\Models; +use Fenos\Notifynder\Builder\Notification as BuilderNotification; use Illuminate\Database\Eloquent\Model; class Notification extends Model @@ -23,10 +24,14 @@ class Notification extends Model 'extra' => 'array', ]; - public function __construct(array $attributes = []) + public function __construct($attributes = []) { $this->fillable($this->mergeFillables()); + if($attributes instanceof BuilderNotification) { + $attributes = $attributes->toArray(); + } + parent::__construct($attributes); } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 7b01c66..8b76d8c 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -4,8 +4,12 @@ use Fenos\Notifynder\Collections\Config; use Fenos\Notifynder\Contracts\ConfigContract; -use Fenos\Notifynder\Contracts\NotifynderContract; +use Fenos\Notifynder\Contracts\NotifynderManagerContract; +use Fenos\Notifynder\Contracts\SenderManagerContract; use Fenos\Notifynder\Managers\NotifynderManager; +use Fenos\Notifynder\Managers\SenderManager; +use Fenos\Notifynder\Senders\MultipleSender; +use Fenos\Notifynder\Senders\SingleSender; use Illuminate\Support\ServiceProvider; class NotifynderServiceProvider extends ServiceProvider @@ -14,7 +18,10 @@ public function register() { $this->bindContracts(); $this->bindConfig(); + $this->bindSender(); $this->bindNotifynder(); + + $this->registerSenders(); } public function boot() @@ -28,7 +35,8 @@ public function boot() */ protected function bindContracts() { - $this->app->bind(NotifynderContract::class, 'notifynder'); + $this->app->bind(NotifynderManagerContract::class, 'notifynder'); + $this->app->bind(SenderManagerContract::class, 'notifynder.sender'); $this->app->bind(ConfigContract::class, 'notifynder.config'); } @@ -42,6 +50,16 @@ protected function bindConfig() }); } + /** + * Bind notifynder config. + */ + protected function bindSender() + { + $this->app->singleton('notifynder.sender', function ($app) { + return new SenderManager(); + }); + } + /** * Bind notifynder manager. */ @@ -49,14 +67,21 @@ protected function bindNotifynder() { $this->app->singleton('notifynder', function ($app) { return new NotifynderManager( - $app['notifynder.category'], - $app['notifynder.sender'], - $app['notifynder.notification'], - $app['notifynder.dispatcher'], - $app['notifynder.group'] + $app['notifynder.sender'] ); }); } + + public function registerSenders() + { + app('notifynder')->extend('sendSingle', function (array $notifications) { + return new SingleSender($notifications); + }); + + app('notifynder')->extend('sendMultiple', function (array $notifications) { + return new MultipleSender($notifications); + }); + } /** * Publish config file. diff --git a/src/Notifynder/Senders/MultipleSender.php b/src/Notifynder/Senders/MultipleSender.php new file mode 100644 index 0000000..bbbc2bf --- /dev/null +++ b/src/Notifynder/Senders/MultipleSender.php @@ -0,0 +1,39 @@ +notifications = $notifications; + $this->database = app('db'); + } + + public function send(SenderManagerContract $sender) + { + $model = notifynder_config()->getNotificationModel(); + $table = (new $model())->getTable(); + + $this->database->beginTransaction(); + $stackId = $this->database + ->table($table) + ->max('stack_id') + 1; + foreach ($this->notifications as $key => $notification) { + $this->notifications[$key] = $this->notifications[$key]->toArray(); + $this->notifications[$key]['stack_id'] = $stackId; + } + $insert = $this->database + ->table($table) + ->insert($this->notifications); + $this->database->commit(); + return $insert; + } +} \ No newline at end of file diff --git a/src/Notifynder/Senders/SingleSender.php b/src/Notifynder/Senders/SingleSender.php new file mode 100644 index 0000000..df4ac72 --- /dev/null +++ b/src/Notifynder/Senders/SingleSender.php @@ -0,0 +1,22 @@ +notification = array_values($notifications)[0]; + } + + public function send(SenderManagerContract $sender) + { + $notification = new Notification($this->notification); + return $notification->save(); + } +} \ No newline at end of file diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php new file mode 100644 index 0000000..cbe9a7d --- /dev/null +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -0,0 +1,81 @@ +setExpectedException(BadMethodCallException::class); + + $manager = app('notifynder'); + $manager->undefinedMethod(); + } + + public function testGetBuilderInstance() + { + $manager = app('notifynder'); + $builder = $manager->builder(); + + $this->assertInstanceOf(Builder::class, $builder); + } + + public function testGetSenderInstance() + { + $manager = app('notifynder'); + $sender = $manager->sender(); + + $this->assertInstanceOf(SenderManager::class, $sender); + } + + public function testBuildSingleNotification() + { + $manager = app('notifynder'); + $notification = $manager->category(1) + ->from(1) + ->to(2) + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + } + + public function testBuildMultipleNotifications() + { + $datas = [2, 3, 4]; + $manager = app('notifynder'); + $notifications = $manager->loop($datas, function ($builder, $data) { + $builder->category(1) + ->from(1) + ->to($data); + })->getNotifications(); + + $this->assertInternalType('array', $notifications); + $this->assertCount(count($datas), $notifications); + } + + public function testSendSingleNotification() + { + $manager = app('notifynder'); + $sent = $manager->category(1) + ->from(1) + ->to(2) + ->send(); + + $this->assertTrue($sent); + } + + public function testSendMultipleNotifications() + { + $datas = [2, 3, 4]; + $manager = app('notifynder'); + $sent = $manager->loop($datas, function ($builder, $data) { + $builder->category(1) + ->from(1) + ->to($data); + })->send(); + + $this->assertTrue($sent); + } +} \ No newline at end of file From afe03c3b494e555e79a4a4a4a5a365322e2de247 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 20 Jun 2016 11:42:28 -0400 Subject: [PATCH 120/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Builder.php | 2 +- src/Notifynder/Contracts/SenderContract.php | 3 ++- src/Notifynder/Contracts/SenderManagerContract.php | 3 ++- src/Notifynder/Managers/NotifynderManager.php | 14 ++++++++++---- src/Notifynder/Managers/SenderManager.php | 11 +++++++---- src/Notifynder/Models/Notification.php | 2 +- src/Notifynder/NotifynderServiceProvider.php | 2 +- src/Notifynder/Senders/MultipleSender.php | 5 +++-- src/Notifynder/Senders/SingleSender.php | 4 +++- .../integration/Managers/NotifynderManagerTest.php | 2 +- 10 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 9058e59..7d737f0 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -28,7 +28,7 @@ public function category($category) $categoryId = $category; if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); - } elseif (!is_numeric($category)) { + } elseif (! is_numeric($category)) { $categoryId = NotificationCategory::byName($category)->findOrFail()->getKey(); } diff --git a/src/Notifynder/Contracts/SenderContract.php b/src/Notifynder/Contracts/SenderContract.php index 8cb7966..3cd4b82 100644 --- a/src/Notifynder/Contracts/SenderContract.php +++ b/src/Notifynder/Contracts/SenderContract.php @@ -1,4 +1,5 @@ builder(true); $this->builder->category($category); + return $this; } @@ -34,21 +35,24 @@ public function loop($data, Closure $callback) { $this->builder(true); $this->builder->loop($data, $callback); + return $this; } public function builder($new = false) { - if(is_null($this->builder) || $new) { + if (is_null($this->builder) || $new) { $this->builder = new Builder(); } + return $this->builder; } - + public function send() { $sent = $this->sender->send($this->builder->getNotifications()); $this->reset(); + return $sent; } @@ -72,14 +76,16 @@ public function __call($name, $arguments) if (Str::startsWith($name, 'send')) { $sent = $this->sender->sendWithCustomSender($name, $this->builder->getNotifications()); $this->reset(); + return $sent; } - if($this->builder instanceof Builder && method_exists($this->builder, $name)) { + if ($this->builder instanceof Builder && method_exists($this->builder, $name)) { $result = call_user_func_array([$this->builder, $name], $arguments); - if(Str::startsWith($name, 'get')) { + if (Str::startsWith($name, 'get')) { return $result; } + return $this; } diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index de7204d..77735b0 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -1,4 +1,5 @@ sendSingle($notifications); } + return $this->sendMultiple($notifications); } @@ -33,14 +35,15 @@ public function getSender($name) public function extend($name, Closure $sender) { $this->senders[$name] = $sender; + return true; } public function sendWithCustomSender($name, array $notifications) { - if($this->hasSender($name)) { + if ($this->hasSender($name)) { $sender = call_user_func_array($this->getSender($name), [$notifications]); - if($sender instanceof SenderContract) { + if ($sender instanceof SenderContract) { return (bool) $sender->send($this); } throw new BadFunctionCallException("The sender [{$name}] hasn't returned an instance of ".SenderContract::class); @@ -56,4 +59,4 @@ public function __call($name, $arguments) throw new BadMethodCallException('No argument passed to the custom sender, please provide notifications array'); } -} \ No newline at end of file +} diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 6b90d35..def62d6 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -28,7 +28,7 @@ public function __construct($attributes = []) { $this->fillable($this->mergeFillables()); - if($attributes instanceof BuilderNotification) { + if ($attributes instanceof BuilderNotification) { $attributes = $attributes->toArray(); } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 8b76d8c..4624fcc 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -71,7 +71,7 @@ protected function bindNotifynder() ); }); } - + public function registerSenders() { app('notifynder')->extend('sendSingle', function (array $notifications) { diff --git a/src/Notifynder/Senders/MultipleSender.php b/src/Notifynder/Senders/MultipleSender.php index bbbc2bf..1f91e4f 100644 --- a/src/Notifynder/Senders/MultipleSender.php +++ b/src/Notifynder/Senders/MultipleSender.php @@ -1,6 +1,6 @@ table($table) ->insert($this->notifications); $this->database->commit(); + return $insert; } -} \ No newline at end of file +} diff --git a/src/Notifynder/Senders/SingleSender.php b/src/Notifynder/Senders/SingleSender.php index df4ac72..97dc286 100644 --- a/src/Notifynder/Senders/SingleSender.php +++ b/src/Notifynder/Senders/SingleSender.php @@ -1,4 +1,5 @@ notification); + return $notification->save(); } -} \ No newline at end of file +} diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php index cbe9a7d..4068302 100644 --- a/tests/integration/Managers/NotifynderManagerTest.php +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -78,4 +78,4 @@ public function testSendMultipleNotifications() $this->assertTrue($sent); } -} \ No newline at end of file +} From d83c2fe97d448006a9d031ebcf96c6fa2d1a77bb Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 20 Jun 2016 17:47:03 +0200 Subject: [PATCH 121/210] update readme --- README.md | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 951335e..ca0cb59 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Notifynder 3.2 - Laravel 5 -========================== +Notifynder 4 - Laravel 5 +======================== [![GitHub release](https://img.shields.io/github/release/fenos/Notifynder.svg?style=flat-square)](https://github.com/fenos/Notifynder/releases) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/fenos/Notifynder/master/LICENSE) @@ -34,7 +34,7 @@ Documentation: **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)** Add it on your `composer.json` - "fenos/notifynder": "^3.2" + "fenos/notifynder": "^4.0" and run @@ -70,35 +70,7 @@ Run the migration php artisan migrate -### Quick Usage ### +## Usage ## -Set up category of notification, think about it as the -body of the notification: - - php artisan notifynder:create:category "user.following" "{from.username} started to follow you" - -To send a notification with notifynder, that's all -you have to do. - -~~~php -Notifynder::category('user.following') - ->from($from_user_id) - ->to($to_user_id) - ->url('http://www.yourwebsite.com/page') - ->send(); -~~~ - -**Retrieving Notifications** - -~~~php -// @return Collection -Notifynder::getAll($user_id,$limit,$paginateBool); -~~~ - -**Reading Notifications:** -~~~php -// @return number of notifications read -Notifynder::readAll($user_id); -~~~ - -To know more, such as the advance usage of Notifynder Visit the **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)**. +This Branch isn't ready for any kind of usage! It's development in progress and will bring a whole new code-base for this package. +Everyone is welcome to support us or give feedback for the new major version in our Slack Team. \ No newline at end of file From 73f08606698991b1b2f17bf100d8ba6fb85d0d19 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 21 Jun 2016 17:25:27 +0200 Subject: [PATCH 122/210] add notification parser --- src/Notifynder/Collections/Config.php | 15 +++++++ src/Notifynder/Contracts/ConfigContract.php | 6 +++ .../Exceptions/ExtraParamsException.php | 9 ++++ src/Notifynder/Helpers/helpers.php | 25 ++++++++++- src/Notifynder/Models/Notification.php | 26 +++++++++++ src/Notifynder/Parsers/NotificationParser.php | 45 +++++++++++++++++++ .../Managers/NotifynderManagerTest.php | 14 +++++- 7 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 src/Notifynder/Exceptions/ExtraParamsException.php create mode 100644 src/Notifynder/Parsers/NotificationParser.php diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index 99e75a3..c552711 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -20,6 +20,16 @@ public function isPolymorphic() return (bool) $this->get('polymorphic'); } + public function isStrict() + { + return (bool) $this->get('strict_extra'); + } + + public function isTranslated() + { + return (bool) $this->get('translation.enabled'); + } + public function getNotificationModel() { $class = $this->get('notification_model'); @@ -49,6 +59,11 @@ public function getAdditionalRequiredFields() return Arr::flatten($this->get('additional_fields.required', [])); } + public function getTranslationDomain() + { + return $this->get('translation.domain', 'notifynder'); + } + public function get($key, $default = null) { return Arr::get($this->items, $key, $default); diff --git a/src/Notifynder/Contracts/ConfigContract.php b/src/Notifynder/Contracts/ConfigContract.php index 8337f77..35ede10 100644 --- a/src/Notifynder/Contracts/ConfigContract.php +++ b/src/Notifynder/Contracts/ConfigContract.php @@ -6,6 +6,10 @@ interface ConfigContract { public function isPolymorphic(); + public function isStrict(); + + public function isTranslated(); + public function getNotificationModel(); public function getNotifiedModel(); @@ -14,6 +18,8 @@ public function getAdditionalFields(); public function getAdditionalRequiredFields(); + public function getTranslationDomain(); + public function get($key, $default); public function has($key); diff --git a/src/Notifynder/Exceptions/ExtraParamsException.php b/src/Notifynder/Exceptions/ExtraParamsException.php new file mode 100644 index 0000000..95a0593 --- /dev/null +++ b/src/Notifynder/Exceptions/ExtraParamsException.php @@ -0,0 +1,9 @@ +get($key, $default); } } + +if (! function_exists('notifynder_mixed_get')) { + function notifynder_mixed_get($object, $key, $default = null) + { + if (is_null($key) || trim($key) == '') { + return ''; + } + foreach (explode('.', $key) as $segment) { + if (is_object($object) && isset($object->{$segment})) { + $object = $object->{$segment}; + } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { + $object = $object->__get($segment); + } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { + $object = $object->getAttribute($segment); + } elseif (is_array($object) && array_key_exists($segment, $object)) { + $object = array_get($object, $segment, $default); + } else { + return value($default); + } + } + return $object; + } +} \ No newline at end of file diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index def62d6..0c50903 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -3,6 +3,7 @@ namespace Fenos\Notifynder\Models; use Fenos\Notifynder\Builder\Notification as BuilderNotification; +use Fenos\Notifynder\Parsers\NotificationParser; use Illuminate\Database\Eloquent\Model; class Notification extends Model @@ -20,6 +21,10 @@ class Notification extends Model 'stack_id', ]; + protected $appends = [ + 'text', + ]; + protected $casts = [ 'extra' => 'array', ]; @@ -69,4 +74,25 @@ protected function mergeFillables() return $fillables; } + + public function getTemplateBodyAttribute() + { + if (notifynder_config()->isTranslated()) { + $key = notifynder_config()->getTranslationDomain().'.'.$this->category->name; + $trans = trans($key); + if ($trans != $key) { + return $trans; + } + } + return $this->category->text; + } + + public function getTextAttribute() + { + if(!array_key_exists('text', $this->attributes)) { + $notifynderParse = new NotificationParser(); + $this->attributes['text'] = $notifynderParse->parse($this); + } + return $this->attributes['text']; + } } diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php new file mode 100644 index 0000000..297cc9f --- /dev/null +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -0,0 +1,45 @@ +template_body; + + $specialValues = $this->getValues($text); + if (count($specialValues) > 0) { + $specialValues = array_filter($specialValues, function ($value) use ($notification) { + return isset($notification->$value) || starts_with($value, ['extra.', 'to.', 'from.']); + }); + + foreach ($specialValues as $replacer) { + $replace = notifynder_mixed_get($notification, $replacer); + if (empty($replace) && notifynder_config()->isStrict()) { + throw new ExtraParamsException("The following [$replacer] param required from your category is missing."); + } + $text = $this->replace($text, $replace, $replacer); + } + } + + return $text; + } + + protected function getValues($body) + { + $values = []; + preg_match_all(self::RULE, $body, $values); + return $values[1]; + } + + protected function replace($body, $valueMatch, $replacer) + { + $body = str_replace('{'.$replacer.'}', $valueMatch, $body); + return $body; + } +} \ No newline at end of file diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php index 4068302..1d15430 100644 --- a/tests/integration/Managers/NotifynderManagerTest.php +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -1,7 +1,9 @@ to(2) ->getNotification(); - $this->assertInstanceOf(Notification::class, $notification); + $this->assertInstanceOf(BuilderNotification::class, $notification); } public function testBuildMultipleNotifications() @@ -64,6 +66,10 @@ public function testSendSingleNotification() ->send(); $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(1, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); } public function testSendMultipleNotifications() @@ -77,5 +83,9 @@ public function testSendMultipleNotifications() })->send(); $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(count($datas), $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); } } From 94cdcc044dcf9d662d66cb6dd79edb9de28dc962 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 21 Jun 2016 17:25:40 +0200 Subject: [PATCH 123/210] enable travis --- .old.travis.yml => .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .old.travis.yml => .travis.yml (92%) diff --git a/.old.travis.yml b/.travis.yml similarity index 92% rename from .old.travis.yml rename to .travis.yml index d701d03..5796ba3 100755 --- a/.old.travis.yml +++ b/.travis.yml @@ -34,9 +34,9 @@ before_script: ## Run test Scripts script: - - vendor/bin/phpspec run +## - vendor/bin/phpspec run - vendor/bin/phpunit - - php CoverageChecker.php clover.xml 65 +## - php CoverageChecker.php clover.xml 65 ## Send Build Notifications to Slack notifications: From d732ee75763e3095a6d3c31fcea16cd68ded7c2e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 21 Jun 2016 11:25:53 -0400 Subject: [PATCH 124/210] Applied fixes from StyleCI --- src/Notifynder/Exceptions/ExtraParamsException.php | 4 ++-- src/Notifynder/Helpers/helpers.php | 7 ++++--- src/Notifynder/Models/Notification.php | 4 +++- src/Notifynder/Parsers/NotificationParser.php | 5 ++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Notifynder/Exceptions/ExtraParamsException.php b/src/Notifynder/Exceptions/ExtraParamsException.php index 95a0593..ce26243 100644 --- a/src/Notifynder/Exceptions/ExtraParamsException.php +++ b/src/Notifynder/Exceptions/ExtraParamsException.php @@ -1,9 +1,9 @@ {$segment})) { $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { + } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { + } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { $object = $object->getAttribute($segment); } elseif (is_array($object) && array_key_exists($segment, $object)) { $object = array_get($object, $segment, $default); @@ -36,6 +36,7 @@ function notifynder_mixed_get($object, $key, $default = null) return value($default); } } + return $object; } -} \ No newline at end of file +} diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 0c50903..cac7f4b 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -84,15 +84,17 @@ public function getTemplateBodyAttribute() return $trans; } } + return $this->category->text; } public function getTextAttribute() { - if(!array_key_exists('text', $this->attributes)) { + if (! array_key_exists('text', $this->attributes)) { $notifynderParse = new NotificationParser(); $this->attributes['text'] = $notifynderParse->parse($this); } + return $this->attributes['text']; } } diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index 297cc9f..435d1da 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -1,4 +1,5 @@ Date: Wed, 22 Jun 2016 15:29:36 +0200 Subject: [PATCH 125/210] bring managers to 100% coverage --- .../Managers/NotifynderManagerTest.php | 15 +++++++++ .../Managers/SenderManagerTest.php | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/integration/Managers/SenderManagerTest.php diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php index 1d15430..60a8bdf 100644 --- a/tests/integration/Managers/NotifynderManagerTest.php +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -88,4 +88,19 @@ public function testSendMultipleNotifications() $this->assertCount(count($datas), $notifications); $this->assertInstanceOf(EloquentCollection::class, $notifications); } + + public function testSendSingleSpecificNotification() + { + $manager = app('notifynder'); + $sent = $manager->category(1) + ->from(1) + ->to(2) + ->sendSingle(); + + $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(1, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); + } } diff --git a/tests/integration/Managers/SenderManagerTest.php b/tests/integration/Managers/SenderManagerTest.php new file mode 100644 index 0000000..a48adf0 --- /dev/null +++ b/tests/integration/Managers/SenderManagerTest.php @@ -0,0 +1,31 @@ +setExpectedException(BadMethodCallException::class); + + $manager = app('notifynder.sender'); + $manager->sendSingle(); + } + + public function testCallUndefinedMethod() + { + $this->setExpectedException(BadMethodCallException::class); + + $manager = app('notifynder.sender'); + $manager->undefinedMethod([]); + } + + public function testCallFailingSender() + { + $this->setExpectedException(BadFunctionCallException::class); + + $manager = app('notifynder.sender'); + $manager->extend('sendFail', function() { + return null; + }); + $manager->sendFail([]); + } +} From 5148395b4ce4fdd67ffff0e82ee4e81161ce6d32 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 15:42:03 +0200 Subject: [PATCH 126/210] bring config to 100% coverage --- tests/integration/Collections/ConfigTest.php | 111 +++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/integration/Collections/ConfigTest.php diff --git a/tests/integration/Collections/ConfigTest.php b/tests/integration/Collections/ConfigTest.php new file mode 100644 index 0000000..44738af --- /dev/null +++ b/tests/integration/Collections/ConfigTest.php @@ -0,0 +1,111 @@ +assertInternalType('bool', $config->isPolymorphic()); + } + + public function testIsStrict() + { + $config = app('notifynder.config'); + $this->assertInternalType('bool', $config->isStrict()); + } + + public function testIsTranslated() + { + $config = app('notifynder.config'); + $this->assertInternalType('bool', $config->isTranslated()); + } + + public function testGetNotificationModel() + { + $config = app('notifynder.config'); + $this->assertInternalType('string', $config->getNotificationModel()); + $this->assertSame(Notification::class, $config->getNotificationModel()); + } + + public function testGetNotificationModelFallback() + { + $config = app('notifynder.config'); + $config->set('notification_model', 'undefined_class_name'); + $this->assertInternalType('string', $config->getNotificationModel()); + $this->assertSame(Notification::class, $config->getNotificationModel()); + } + + public function testGetNotifiedModel() + { + $config = app('notifynder.config'); + $this->assertInternalType('string', $config->getNotifiedModel()); + $this->assertSame(User::class, $config->getNotifiedModel()); + } + + public function testGetNotifiedModelFail() + { + $this->setExpectedException(InvalidArgumentException::class); + + $config = app('notifynder.config'); + $config->set('model', 'undefined_class_name'); + $config->getNotifiedModel(); + } + + public function testGetAdditionalFields() + { + $config = app('notifynder.config'); + $this->assertInternalType('array', $config->getAdditionalFields()); + $this->assertSame([], $config->getAdditionalFields()); + } + + public function testGetAdditionalRequiredFields() + { + $config = app('notifynder.config'); + $this->assertInternalType('array', $config->getAdditionalRequiredFields()); + $this->assertSame([], $config->getAdditionalRequiredFields()); + } + + public function testGetTranslationDomain() + { + $config = app('notifynder.config'); + $this->assertInternalType('string', $config->getTranslationDomain()); + $this->assertSame('notifynder', $config->getTranslationDomain()); + } + + public function testHasTrue() + { + $config = app('notifynder.config'); + $this->assertTrue($config->has('polymorphic')); + } + + public function testHasFalse() + { + $config = app('notifynder.config'); + $this->assertFalse($config->has('undefined_config_key')); + } + + public function testSet() + { + $config = app('notifynder.config'); + $config->set('polymorphic', true); + $this->assertTrue($config->get('polymorphic')); + } + + public function testGetOverloaded() + { + $config = app('notifynder.config'); + $this->assertInternalType('bool', $config->polymorphic); + } + + public function testSetOverloaded() + { + $config = app('notifynder.config'); + + $config->polymorphic = true; + $this->assertInternalType('bool', $config->polymorphic); + $this->assertTrue($config->get('polymorphic')); + } +} From 287c9b304fe7cb69c43f1a9ed38d2732d5ad256f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 15:44:20 +0200 Subject: [PATCH 127/210] bring exceptions to 100% coverage --- tests/integration/Builder/BuilderTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php index 86eb4c3..fd54688 100644 --- a/tests/integration/Builder/BuilderTest.php +++ b/tests/integration/Builder/BuilderTest.php @@ -76,6 +76,19 @@ public function testCreateSingleUnvalidNotification() ->getNotification(); } + public function testCreateSingleCatchedUnvalidNotificationW() + { + try { + $builder = new Builder(); + $builder + ->from(1) + ->to(2) + ->getNotification(); + } catch(UnvalidNotificationException $e) { + $this->assertInstanceOf(Notification::class, $e->getNotification()); + } + } + public function testCreateMultipleNotifications() { $datas = [2, 3, 4]; From 18b78c120d4490ff94b16af6ef6dd1da8f5c11c0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 15:53:32 +0200 Subject: [PATCH 128/210] add helpers unittests --- tests/integration/Helpers/HelpersTest.php | 16 ++++ tests/integration/Helpers/TypeCheckerTest.php | 75 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/integration/Helpers/HelpersTest.php create mode 100644 tests/integration/Helpers/TypeCheckerTest.php diff --git a/tests/integration/Helpers/HelpersTest.php b/tests/integration/Helpers/HelpersTest.php new file mode 100644 index 0000000..d8048a8 --- /dev/null +++ b/tests/integration/Helpers/HelpersTest.php @@ -0,0 +1,16 @@ +assertInstanceOf(Config::class, notifynder_config()); + } + + public function testNotifynderConfigGet() + { + $this->assertInternalType('bool', notifynder_config('polymorphic')); + } +} \ No newline at end of file diff --git a/tests/integration/Helpers/TypeCheckerTest.php b/tests/integration/Helpers/TypeCheckerTest.php new file mode 100644 index 0000000..1f91831 --- /dev/null +++ b/tests/integration/Helpers/TypeCheckerTest.php @@ -0,0 +1,75 @@ +checker = new TypeChecker(); + } + + public function testIsString() + { + $this->assertTrue($this->checker->isString('hello world')); + } + + public function testIsStringFail() + { + $this->setExpectedException(InvalidArgumentException::class); + + $this->assertTrue($this->checker->isString(15)); + } + + public function testIsNumeric() + { + $this->assertTrue($this->checker->isNumeric(15)); + } + + public function testIsNumericFail() + { + $this->setExpectedException(InvalidArgumentException::class); + + $this->assertTrue($this->checker->isNumeric('hello world')); + } + + public function testIsDate() + { + $this->assertTrue($this->checker->isDate(Carbon::now())); + } + + public function testIsDateFail() + { + $this->setExpectedException(InvalidArgumentException::class); + + $this->assertTrue($this->checker->isDate('hello world')); + } + + public function testIsArray() + { + $this->assertTrue($this->checker->isArray([1,2,3])); + } + + public function testIsArrayFail() + { + $this->setExpectedException(InvalidArgumentException::class); + + $this->assertTrue($this->checker->isArray([])); + } + + public function testIsIterable() + { + $this->assertTrue($this->checker->isIterable(collect([1,2,3]))); + } + + public function testIsIterableFail() + { + $this->setExpectedException(InvalidArgumentException::class); + + $this->assertTrue($this->checker->isIterable([])); + } +} \ No newline at end of file From e16baea8894aab89ae0f82961a34d79f005ff50a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 09:53:45 -0400 Subject: [PATCH 129/210] Applied fixes from StyleCI --- tests/integration/Builder/BuilderTest.php | 2 +- tests/integration/Helpers/HelpersTest.php | 2 +- tests/integration/Helpers/TypeCheckerTest.php | 6 +++--- tests/integration/Managers/SenderManagerTest.php | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php index fd54688..a3b0167 100644 --- a/tests/integration/Builder/BuilderTest.php +++ b/tests/integration/Builder/BuilderTest.php @@ -84,7 +84,7 @@ public function testCreateSingleCatchedUnvalidNotificationW() ->from(1) ->to(2) ->getNotification(); - } catch(UnvalidNotificationException $e) { + } catch (UnvalidNotificationException $e) { $this->assertInstanceOf(Notification::class, $e->getNotification()); } } diff --git a/tests/integration/Helpers/HelpersTest.php b/tests/integration/Helpers/HelpersTest.php index d8048a8..f46bf21 100644 --- a/tests/integration/Helpers/HelpersTest.php +++ b/tests/integration/Helpers/HelpersTest.php @@ -13,4 +13,4 @@ public function testNotifynderConfigGet() { $this->assertInternalType('bool', notifynder_config('polymorphic')); } -} \ No newline at end of file +} diff --git a/tests/integration/Helpers/TypeCheckerTest.php b/tests/integration/Helpers/TypeCheckerTest.php index 1f91831..5a51176 100644 --- a/tests/integration/Helpers/TypeCheckerTest.php +++ b/tests/integration/Helpers/TypeCheckerTest.php @@ -51,7 +51,7 @@ public function testIsDateFail() public function testIsArray() { - $this->assertTrue($this->checker->isArray([1,2,3])); + $this->assertTrue($this->checker->isArray([1, 2, 3])); } public function testIsArrayFail() @@ -63,7 +63,7 @@ public function testIsArrayFail() public function testIsIterable() { - $this->assertTrue($this->checker->isIterable(collect([1,2,3]))); + $this->assertTrue($this->checker->isIterable(collect([1, 2, 3]))); } public function testIsIterableFail() @@ -72,4 +72,4 @@ public function testIsIterableFail() $this->assertTrue($this->checker->isIterable([])); } -} \ No newline at end of file +} diff --git a/tests/integration/Managers/SenderManagerTest.php b/tests/integration/Managers/SenderManagerTest.php index a48adf0..9d50554 100644 --- a/tests/integration/Managers/SenderManagerTest.php +++ b/tests/integration/Managers/SenderManagerTest.php @@ -23,8 +23,7 @@ public function testCallFailingSender() $this->setExpectedException(BadFunctionCallException::class); $manager = app('notifynder.sender'); - $manager->extend('sendFail', function() { - return null; + $manager->extend('sendFail', function () { }); $manager->sendFail([]); } From 219c93b476ad7bac58af520774dd0f061c74ffa5 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 16:10:15 +0200 Subject: [PATCH 130/210] fix phpunit code directory --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index a49ef22..b75df8f 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,7 +16,7 @@ - ./src + ./src/Notifynder From 245b4fff54a48754aad976f7bfcdfb2010d6723e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 16:12:10 +0200 Subject: [PATCH 131/210] .idea shouldn't be in repo gitignore - put it in developer global gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0679353..dfd6caa 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /vendor -composer.lock -.idea \ No newline at end of file +composer.lock \ No newline at end of file From 4f25d1492cfceef9b4d749e324ccefd94bfe1843 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 16:24:01 +0200 Subject: [PATCH 132/210] just allow senders starting with "send" --- src/Notifynder/Managers/SenderManager.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index 77735b0..b1caef9 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -8,6 +8,7 @@ use Fenos\Notifynder\Contracts\SenderContract; use Fenos\Notifynder\Contracts\SenderManagerContract; use Illuminate\Support\Arr; +use Illuminate\Support\Str; class SenderManager implements SenderManagerContract { @@ -34,9 +35,11 @@ public function getSender($name) public function extend($name, Closure $sender) { - $this->senders[$name] = $sender; - - return true; + if (Str::startsWith($name, 'send')) { + $this->senders[$name] = $sender; + return true; + } + return false; } public function sendWithCustomSender($name, array $notifications) From 24170d694c6a876604f0b52f2e331ef2eb8b3176 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 22 Jun 2016 10:27:32 -0400 Subject: [PATCH 133/210] Applied fixes from StyleCI --- src/Notifynder/Managers/SenderManager.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index b1caef9..ebab28b 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -37,8 +37,10 @@ public function extend($name, Closure $sender) { if (Str::startsWith($name, 'send')) { $this->senders[$name] = $sender; + return true; } + return false; } From 5903bf692844fcd7681f7da7553040b19686a365 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 14:33:38 +0200 Subject: [PATCH 134/210] Issue #71 add `OnceSender` class --- src/Notifynder/Models/Notification.php | 10 +++ src/Notifynder/NotifynderServiceProvider.php | 5 ++ src/Notifynder/Senders/OnceSender.php | 51 ++++++++++++++ .../Managers/NotifynderManagerTest.php | 66 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 src/Notifynder/Senders/OnceSender.php diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index cac7f4b..6e94860 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -97,4 +97,14 @@ public function getTextAttribute() return $this->attributes['text']; } + + public function read() + { + $this->update(['read' => 1]); + } + + public function unread() + { + $this->update(['read' => 0]); + } } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 4624fcc..7de1063 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -9,6 +9,7 @@ use Fenos\Notifynder\Managers\NotifynderManager; use Fenos\Notifynder\Managers\SenderManager; use Fenos\Notifynder\Senders\MultipleSender; +use Fenos\Notifynder\Senders\OnceSender; use Fenos\Notifynder\Senders\SingleSender; use Illuminate\Support\ServiceProvider; @@ -81,6 +82,10 @@ public function registerSenders() app('notifynder')->extend('sendMultiple', function (array $notifications) { return new MultipleSender($notifications); }); + + app('notifynder')->extend('sendOnce', function (array $notifications) { + return new OnceSender($notifications); + }); } /** diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php new file mode 100644 index 0000000..09573df --- /dev/null +++ b/src/Notifynder/Senders/OnceSender.php @@ -0,0 +1,51 @@ +notifications = $notifications; + } + + public function send(SenderManagerContract $sender) + { + $model = notifynder_config()->getNotificationModel(); + + $success = true; + foreach($this->notifications as $notification) { + $query = $model::query(); + if (!($query instanceof EloquentBuilder)) { + throw new BadMethodCallException("The query method hasn't return an instance of the eloquent query builder."); + } + $query + ->where('from_id', $notification->from_id) + ->where('from_type', $notification->from_type) + ->where('to_id', $notification->to_id) + ->where('to_type', $notification->to_type) + ->where('category_id', $notification->category_id); + if (isset($notification->extra) && !empty($notification->extra)) { + $extra = $notification->extra; + if(is_array($extra)) { + $extra = json_encode($extra); + } + $query->where('extra', $extra); + } + if (!$query->exists()) { + $success = $sender->send([$notification]) ? $success : false; + } else { + $notification = $query->first(); + $notification->touch(); + $notification->unread(); + } + } + return $success; + } +} \ No newline at end of file diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php index 60a8bdf..2817078 100644 --- a/tests/integration/Managers/NotifynderManagerTest.php +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -1,5 +1,6 @@ assertCount(1, $notifications); $this->assertInstanceOf(EloquentCollection::class, $notifications); } + + public function testSendOnceSameNotifications() + { + $manager = app('notifynder'); + $sent = $manager->category(1) + ->from(1) + ->to(2) + ->sendOnce(); + $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(1, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); + $notificationFirst = $notifications->first(); + $this->assertInstanceOf(Notification::class, $notificationFirst); + + $this->assertEquals(0, $notificationFirst->read); + $notificationFirst->read(); + $this->assertEquals(1, $notificationFirst->read); + + sleep(1); + + $sent = $manager->category(1) + ->from(1) + ->to(2) + ->sendOnce(); + $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(1, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); + $notificationSecond = $notifications->first(); + $this->assertInstanceOf(Notification::class, $notificationSecond); + + $this->assertEquals(0, $notificationSecond->read); + + $this->assertSame($notificationFirst->getKey(), $notificationSecond->getKey()); + $this->assertEquals($notificationFirst->created_at, $notificationSecond->created_at); + $diff = $notificationFirst->updated_at->diffInSeconds($notificationSecond->updated_at); + $this->assertGreaterThan(0, $diff); + } + + public function testSendOnceDifferentNotifications() + { + $manager = app('notifynder'); + $sent = $manager->category(1) + ->from(1) + ->to(2) + ->sendOnce(); + $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(1, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); + + $sent = $manager->category(1) + ->from(2) + ->to(1) + ->sendOnce(); + $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(2, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); + } } From bc348bbd5eccf2358b1c437d4424c1d3c7b8a046 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 08:33:46 -0400 Subject: [PATCH 135/210] Applied fixes from StyleCI --- src/Notifynder/Senders/OnceSender.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 09573df..2ea3bfc 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -1,4 +1,5 @@ getNotificationModel(); $success = true; - foreach($this->notifications as $notification) { + foreach ($this->notifications as $notification) { $query = $model::query(); - if (!($query instanceof EloquentBuilder)) { + if (! ($query instanceof EloquentBuilder)) { throw new BadMethodCallException("The query method hasn't return an instance of the eloquent query builder."); } $query @@ -31,14 +32,14 @@ public function send(SenderManagerContract $sender) ->where('to_id', $notification->to_id) ->where('to_type', $notification->to_type) ->where('category_id', $notification->category_id); - if (isset($notification->extra) && !empty($notification->extra)) { + if (isset($notification->extra) && ! empty($notification->extra)) { $extra = $notification->extra; - if(is_array($extra)) { + if (is_array($extra)) { $extra = json_encode($extra); } $query->where('extra', $extra); } - if (!$query->exists()) { + if (! $query->exists()) { $success = $sender->send([$notification]) ? $success : false; } else { $notification = $query->first(); @@ -46,6 +47,7 @@ public function send(SenderManagerContract $sender) $notification->unread(); } } + return $success; } -} \ No newline at end of file +} From 06275444fcaeff0bdd0b8d08fe3b8f73de15bff5 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 14:41:43 +0200 Subject: [PATCH 136/210] Issue #71 update sender to reduce queries and make it easier to customize --- src/Notifynder/Models/Notification.php | 7 ++++ src/Notifynder/Senders/OnceSender.php | 47 ++++++++++++++------------ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 6e94860..b27b4b0 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -107,4 +107,11 @@ public function unread() { $this->update(['read' => 0]); } + + public function resend() + { + $this->updateTimestamps(); + $this->read = 0; + return $this->save(); + } } diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 09573df..c82621b 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -2,6 +2,7 @@ namespace Fenos\Notifynder\Senders; use BadMethodCallException; +use Fenos\Notifynder\Builder\Notification; use Fenos\Notifynder\Contracts\SenderContract; use Fenos\Notifynder\Contracts\SenderManagerContract; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; @@ -17,35 +18,39 @@ public function __construct(array $notifications) public function send(SenderManagerContract $sender) { - $model = notifynder_config()->getNotificationModel(); $success = true; foreach($this->notifications as $notification) { - $query = $model::query(); - if (!($query instanceof EloquentBuilder)) { - throw new BadMethodCallException("The query method hasn't return an instance of the eloquent query builder."); - } - $query - ->where('from_id', $notification->from_id) - ->where('from_type', $notification->from_type) - ->where('to_id', $notification->to_id) - ->where('to_type', $notification->to_type) - ->where('category_id', $notification->category_id); - if (isset($notification->extra) && !empty($notification->extra)) { - $extra = $notification->extra; - if(is_array($extra)) { - $extra = json_encode($extra); - } - $query->where('extra', $extra); - } + $query = $this->getQuery($notification); if (!$query->exists()) { $success = $sender->send([$notification]) ? $success : false; } else { - $notification = $query->first(); - $notification->touch(); - $notification->unread(); + $query->firstOrFail()->resend(); } } return $success; } + + protected function getQuery(Notification $notification) + { + $model = notifynder_config()->getNotificationModel(); + $query = $model::query(); + if (!($query instanceof EloquentBuilder)) { + throw new BadMethodCallException("The query method hasn't return an instance of the eloquent query builder."); + } + $query + ->where('from_id', $notification->from_id) + ->where('from_type', $notification->from_type) + ->where('to_id', $notification->to_id) + ->where('to_type', $notification->to_type) + ->where('category_id', $notification->category_id); + if (isset($notification->extra) && !empty($notification->extra)) { + $extra = $notification->extra; + if(is_array($extra)) { + $extra = json_encode($extra); + } + $query->where('extra', $extra); + } + return $query; + } } \ No newline at end of file From e9e9b74bc0f7e02b1ec14744e0a8c5c2b8c3bd08 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 08:42:19 -0400 Subject: [PATCH 137/210] Applied fixes from StyleCI --- src/Notifynder/Models/Notification.php | 1 + src/Notifynder/Senders/OnceSender.php | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index b27b4b0..0f70282 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -112,6 +112,7 @@ public function resend() { $this->updateTimestamps(); $this->read = 0; + return $this->save(); } } diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index c82621b..0ac9f64 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -1,4 +1,5 @@ notifications as $notification) { + foreach ($this->notifications as $notification) { $query = $this->getQuery($notification); - if (!$query->exists()) { + if (! $query->exists()) { $success = $sender->send([$notification]) ? $success : false; } else { $query->firstOrFail()->resend(); } } + return $success; } @@ -35,7 +36,7 @@ protected function getQuery(Notification $notification) { $model = notifynder_config()->getNotificationModel(); $query = $model::query(); - if (!($query instanceof EloquentBuilder)) { + if (! ($query instanceof EloquentBuilder)) { throw new BadMethodCallException("The query method hasn't return an instance of the eloquent query builder."); } $query @@ -44,13 +45,14 @@ protected function getQuery(Notification $notification) ->where('to_id', $notification->to_id) ->where('to_type', $notification->to_type) ->where('category_id', $notification->category_id); - if (isset($notification->extra) && !empty($notification->extra)) { + if (isset($notification->extra) && ! empty($notification->extra)) { $extra = $notification->extra; - if(is_array($extra)) { + if (is_array($extra)) { $extra = json_encode($extra); } $query->where('extra', $extra); } + return $query; } -} \ No newline at end of file +} From f2c70d760f1d0c496bea39601ed237bc20406b94 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 16:04:44 +0200 Subject: [PATCH 138/210] Issue #71 make sender more atomic --- src/Notifynder/Senders/OnceSender.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 0ac9f64..cadabce 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -34,11 +34,7 @@ public function send(SenderManagerContract $sender) protected function getQuery(Notification $notification) { - $model = notifynder_config()->getNotificationModel(); - $query = $model::query(); - if (! ($query instanceof EloquentBuilder)) { - throw new BadMethodCallException("The query method hasn't return an instance of the eloquent query builder."); - } + $query = $this->getQueryInstance(); $query ->where('from_id', $notification->from_id) ->where('from_type', $notification->from_type) @@ -55,4 +51,14 @@ protected function getQuery(Notification $notification) return $query; } + + protected function getQueryInstance() + { + $model = notifynder_config()->getNotificationModel(); + $query = $model::query(); + if (! ($query instanceof EloquentBuilder)) { + throw new BadMethodCallException("The query method hasn't return an instance of [".EloquentBuilder::class."]."); + } + return $query; + } } From 9a1527556e191a853f9c19cd968e354d0f533b75 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 10:04:53 -0400 Subject: [PATCH 139/210] Applied fixes from StyleCI --- src/Notifynder/Senders/OnceSender.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index cadabce..67f92a0 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -57,8 +57,9 @@ protected function getQueryInstance() $model = notifynder_config()->getNotificationModel(); $query = $model::query(); if (! ($query instanceof EloquentBuilder)) { - throw new BadMethodCallException("The query method hasn't return an instance of [".EloquentBuilder::class."]."); + throw new BadMethodCallException("The query method hasn't return an instance of [".EloquentBuilder::class.'].'); } + return $query; } } From 6a096c6eb193dba10518bf76d658a9205b022cfc Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 16:57:44 +0200 Subject: [PATCH 140/210] update readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca0cb59..16569bb 100755 --- a/README.md +++ b/README.md @@ -73,4 +73,10 @@ Run the migration ## Usage ## This Branch isn't ready for any kind of usage! It's development in progress and will bring a whole new code-base for this package. -Everyone is welcome to support us or give feedback for the new major version in our Slack Team. \ No newline at end of file +Everyone is welcome to support us or give feedback for the new major version in our Slack Team. + +## Contributors ## + +Thanks for everyone [who contributed](https://github.com/fenos/Notifynder/graphs/contributors) to Notifynder and a special thanks for the most active contributors + +- [Gummibeer](https://github.com/Gummibeer) \ No newline at end of file From 6986635d22748af5bc108255a834e42929addea5 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 17:19:45 +0200 Subject: [PATCH 141/210] update Notifable Trait add SCopes to Notification --- src/Notifynder/Builder/Builder.php | 2 +- src/Notifynder/Models/Notification.php | 17 +++++++ src/Notifynder/Traits/Notifable.php | 15 ++++++ tests/NotifynderTestCase.php | 14 ++++- tests/integration/Traits/NotifableTest.php | 51 +++++++++++++++++++ .../2014_08_01_164248_create_users_table.php | 29 +++++++++++ tests/models/User.php | 6 ++- 7 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 tests/integration/Traits/NotifableTest.php create mode 100644 tests/migrations/2014_08_01_164248_create_users_table.php diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 7d737f0..9d14b58 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -29,7 +29,7 @@ public function category($category) if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); } elseif (! is_numeric($category)) { - $categoryId = NotificationCategory::byName($category)->findOrFail()->getKey(); + $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); } $this->setNotificationData('category_id', $categoryId); diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 0f70282..8e5484b 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -4,6 +4,7 @@ use Fenos\Notifynder\Builder\Notification as BuilderNotification; use Fenos\Notifynder\Parsers\NotificationParser; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class Notification extends Model @@ -115,4 +116,20 @@ public function resend() return $this->save(); } + + public function scopeByCategory(Builder $query, $category) + { + $categoryId = $category; + if($category instanceof NotificationCategory) { + $categoryId = $category->getKey(); + } elseif (! is_numeric($category)) { + $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); + } + return $query->where('category_id', $categoryId); + } + + public function scopeByRead(Builder $query, $read = 1) + { + return $query->where('read', $read); + } } diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 67c87a9..318855b 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -13,4 +13,19 @@ public function notifications() return $this->hasMany($model, 'to_id'); } + + public function notifynder($category) + { + return app('notifynder')->category($category); + } + + public function sendNotificationFrom($category) + { + return $this->notifynder($category)->from($this); + } + + public function sendNotificationTo($category) + { + return $this->notifynder($category)->to($this); + } } diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index 8eeba49..e9dba95 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -1,6 +1,7 @@ app->make('Illuminate\Contracts\Console\Kernel'); app('db')->beginTransaction(); $this->migrate($artisan); + $this->migrate($artisan, '/../../../../tests/migrations'); // Set up the User Test Model app('config')->set('notifynder.notification_model', 'Fenos\Notifynder\Models\Notification'); app('config')->set('notifynder.model', 'Fenos\Tests\Models\User'); @@ -41,11 +43,21 @@ protected function getApplicationTimezone($app) return 'UTC'; } - private function migrate($artisan, $path = '/../../../../src/migrations') + protected function migrate($artisan, $path = '/../../../../src/migrations') { $artisan->call('migrate', [ '--database' => 'testbench', '--path' => $path, ]); } + + protected function createUser(array $attributes = []) + { + $attributes = array_merge([ + 'id' => 1, + 'firstname' => 'John', + 'lastname' => 'Doe', + ], $attributes); + return User::create($attributes); + } } diff --git a/tests/integration/Traits/NotifableTest.php b/tests/integration/Traits/NotifableTest.php new file mode 100644 index 0000000..c3da897 --- /dev/null +++ b/tests/integration/Traits/NotifableTest.php @@ -0,0 +1,51 @@ +createUser(); + $notifynder = $user->notifynder(1); + $this->assertInstanceOf(NotifynderManager::class, $notifynder); + $notifynder->from(1)->to(2); + $builder = $notifynder->builder(); + $this->assertInstanceOf(Builder::class, $builder); + $notification = $builder->getNotification(); + $this->assertInstanceOf(Notification::class, $notification); + $this->assertSame(1, $notification->category_id); + } + + public function testSendNotificationFrom() + { + $user = $this->createUser(); + $notifynder = $user->sendNotificationFrom(1); + $this->assertInstanceOf(NotifynderManager::class, $notifynder); + $notifynder->to(2); + $builder = $notifynder->builder(); + $this->assertInstanceOf(Builder::class, $builder); + $notification = $builder->getNotification(); + $this->assertInstanceOf(Notification::class, $notification); + $this->assertSame(1, $notification->category_id); + $this->assertSame(1, $notification->from_id); + } + + public function testSendNotificationTo() + { + $user = $this->createUser(); + $notifynder = $user->sendNotificationTo(1); + $this->assertInstanceOf(NotifynderManager::class, $notifynder); + $notifynder->from(2); + $builder = $notifynder->builder(); + $this->assertInstanceOf(Builder::class, $builder); + $notification = $builder->getNotification(); + $this->assertInstanceOf(Notification::class, $notification); + $this->assertSame(1, $notification->category_id); + $this->assertSame(1, $notification->to_id); + $notifynder->send(); + $this->assertCount(1, $user->notifications); + } +} diff --git a/tests/migrations/2014_08_01_164248_create_users_table.php b/tests/migrations/2014_08_01_164248_create_users_table.php new file mode 100644 index 0000000..f06972e --- /dev/null +++ b/tests/migrations/2014_08_01_164248_create_users_table.php @@ -0,0 +1,29 @@ +increments('id'); + $table->string('firstname'); + $table->string('lastname'); + $table->timestamps(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('users'); + } +} \ No newline at end of file diff --git a/tests/models/User.php b/tests/models/User.php index c2bbcb0..6235670 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -9,5 +9,9 @@ class User extends Model { use Notifable; - protected $fillable = ['id']; + protected $fillable = [ + 'id', + 'firstname', + 'lastname', + ]; } From 0cd2093332c7770a1a0f96f8d6c6ccda4ef02df4 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 11:20:10 -0400 Subject: [PATCH 142/210] Applied fixes from StyleCI --- src/Notifynder/Models/Notification.php | 3 ++- src/Notifynder/Traits/Notifable.php | 2 +- tests/NotifynderTestCase.php | 1 + tests/migrations/2014_08_01_164248_create_users_table.php | 5 ++++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 8e5484b..ef3857c 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -120,11 +120,12 @@ public function resend() public function scopeByCategory(Builder $query, $category) { $categoryId = $category; - if($category instanceof NotificationCategory) { + if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); } elseif (! is_numeric($category)) { $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); } + return $query->where('category_id', $categoryId); } diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 318855b..9843431 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -13,7 +13,7 @@ public function notifications() return $this->hasMany($model, 'to_id'); } - + public function notifynder($category) { return app('notifynder')->category($category); diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index e9dba95..84b7b1f 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -58,6 +58,7 @@ protected function createUser(array $attributes = []) 'firstname' => 'John', 'lastname' => 'Doe', ], $attributes); + return User::create($attributes); } } diff --git a/tests/migrations/2014_08_01_164248_create_users_table.php b/tests/migrations/2014_08_01_164248_create_users_table.php index f06972e..204f506 100644 --- a/tests/migrations/2014_08_01_164248_create_users_table.php +++ b/tests/migrations/2014_08_01_164248_create_users_table.php @@ -1,6 +1,8 @@ timestamps(); }); } + /** * Reverse the migrations. * @@ -26,4 +29,4 @@ public function down() { Schema::drop('users'); } -} \ No newline at end of file +} From 27249fa9e7bfb0100c74db9a32e29e025c3dde3e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 18:02:23 +0200 Subject: [PATCH 143/210] #167 make `from` nullable and add `anonymous()` to Builder --- src/Notifynder/Builder/Builder.php | 10 ++++- src/Notifynder/Models/Notification.php | 7 +++- src/Notifynder/NotifynderServiceProvider.php | 3 ++ ...56_update_version4_notifications_table.php | 37 +++++++++++++++++++ tests/integration/Builder/BuilderTest.php | 22 ++++++++++- .../Managers/NotifynderManagerTest.php | 21 +++++++++++ 6 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 src/migrations/2016_07_01_153156_update_version4_notifications_table.php diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 9d14b58..63135dd 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -44,6 +44,14 @@ public function from() return $this; } + + public function anonymous() + { + $this->setNotificationData('from_type', null); + $this->setNotificationData('from_id', null); + + return $this; + } public function to() { @@ -64,7 +72,7 @@ public function url($url) public function expire($datetime) { $this->typeChecker->isDate($datetime); - $this->setNotificationData('expire_time', $datetime); + $this->setNotificationData('expires_at', $datetime); return $this; } diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 8e5484b..9da7499 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -18,7 +18,7 @@ class Notification extends Model 'read', 'url', 'extra', - 'expire_time', // ToDo: rename to `expires_at` + 'expires_at', 'stack_id', ]; @@ -117,6 +117,11 @@ public function resend() return $this->save(); } + public function isAnonymous() + { + return is_null($this->from_id); + } + public function scopeByCategory(Builder $query, $category) { $categoryId = $category; diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 7de1063..e797099 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -132,6 +132,9 @@ protected function migration() if (! class_exists('AddStackIdToNotifications')) { $this->publishMigration('2016_05_19_144531_add_stack_id_to_notifications'); } + if (! class_exists('UpdateVersion4NotificationsTable')) { + $this->publishMigration('2016_07_01_153156_update_version4_notifications_table'); + } } /** diff --git a/src/migrations/2016_07_01_153156_update_version4_notifications_table.php b/src/migrations/2016_07_01_153156_update_version4_notifications_table.php new file mode 100644 index 0000000..119a262 --- /dev/null +++ b/src/migrations/2016_07_01_153156_update_version4_notifications_table.php @@ -0,0 +1,37 @@ +bigInteger('from_id')->unsigned()->nullable()->change(); + }); + Schema::table('notifications', function (Blueprint $table) { + $table->renameColumn('expire_time', 'expires_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('notifications', function (Blueprint $table) { + $table->renameColumn('expires_at', 'expire_time'); + }); + Schema::table('notifications', function (Blueprint $table) { + $table->bigInteger('from_id')->unsigned()->change(); + }); + } +} diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php index a3b0167..30148bf 100644 --- a/tests/integration/Builder/BuilderTest.php +++ b/tests/integration/Builder/BuilderTest.php @@ -27,6 +27,26 @@ public function testCreateSingleNotification() $this->assertInstanceOf(Carbon::class, $notification->updated_at); } + public function testCreateSingleAnonymousNotification() + { + $builder = new Builder(); + $notification = $builder + ->category(1) + ->anonymous() + ->to(2) + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + + $this->assertSame(1, $notification->category_id); + $this->assertNull($notification->from_id); + $this->assertNull($notification->from_type); + $this->assertSame(2, $notification->to_id); + $this->assertSame('Fenos\Tests\Models\User', $notification->to_type); + $this->assertInstanceOf(Carbon::class, $notification->created_at); + $this->assertInstanceOf(Carbon::class, $notification->updated_at); + } + public function testCreateSingleNotificationWithAll() { $builder = new Builder(); @@ -47,7 +67,7 @@ public function testCreateSingleNotificationWithAll() $this->assertInternalType('array', $notification->extra); $this->assertCount(1, $notification->extra); $this->assertSame('bar', $notification->extra['foo']); - $this->assertInstanceOf(Carbon::class, $notification->expire_time); + $this->assertInstanceOf(Carbon::class, $notification->expires_at); } public function testCreateSingleNotificationAndGetArray() diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php index 2817078..ece9260 100644 --- a/tests/integration/Managers/NotifynderManagerTest.php +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -73,6 +73,27 @@ public function testSendSingleNotification() $this->assertInstanceOf(EloquentCollection::class, $notifications); } + public function testSendSingleAnonymousNotification() + { + $manager = app('notifynder'); + $sent = $manager->category(1) + ->anonymous() + ->to(2) + ->send(); + + $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(1, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); + $notification = $notifications->first(); + $this->assertInstanceOf(ModelNotification::class, $notification); + $this->assertNull($notification->from); + $this->assertNull($notification->from_id); + $this->assertNull($notification->from_type); + $this->assertTrue($notification->isAnonymous()); + } + public function testSendMultipleNotifications() { $datas = [2, 3, 4]; From 35f850cdc8c5142d2d154c84d76e3a6dd1096301 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 1 Jul 2016 12:02:36 -0400 Subject: [PATCH 144/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 63135dd..40b208e 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -44,7 +44,7 @@ public function from() return $this; } - + public function anonymous() { $this->setNotificationData('from_type', null); From dc6c86b9a56862021944e8164f59180749b4c279 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 11:53:34 +0200 Subject: [PATCH 145/210] also test with the new laravel 5.3 version --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5796ba3..71a0f05 100755 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ env: - LARAVEL_VERSION="5.0.*" - LARAVEL_VERSION="5.1.*" - LARAVEL_VERSION="5.2.*" + - LARAVEL_VERSION="5.3.*" ## Install Dependencies install: From accad7b3f77a4e23d6399a0f21937609e50d1036 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 12:04:17 +0200 Subject: [PATCH 146/210] fix composer version conflict --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b75d4e4..f3f464c 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1", "laracasts/testdummy": "~2.0", - "orchestra/testbench": "~3.0", + "orchestra/testbench": "~3.0|dev-3.3", "doctrine/dbal": "^2.5" }, "autoload": { From 97dbd3f7c8725f447c40b5b94b7f16db3be2dea8 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 12:09:07 +0200 Subject: [PATCH 147/210] remove laravel 5.3 cause it's in dev mode --- .travis.yml | 1 - composer.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71a0f05..5796ba3 100755 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ env: - LARAVEL_VERSION="5.0.*" - LARAVEL_VERSION="5.1.*" - LARAVEL_VERSION="5.2.*" - - LARAVEL_VERSION="5.3.*" ## Install Dependencies install: diff --git a/composer.json b/composer.json index f3f464c..b75d4e4 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1", "laracasts/testdummy": "~2.0", - "orchestra/testbench": "~3.0|dev-3.3", + "orchestra/testbench": "~3.0", "doctrine/dbal": "^2.5" }, "autoload": { From cbf10707058c5c9f5f1a3669ed20ddb0911d3c0b Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 13:49:07 +0200 Subject: [PATCH 148/210] add facade --- src/Notifynder/Facades/Notifynder.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/Notifynder/Facades/Notifynder.php diff --git a/src/Notifynder/Facades/Notifynder.php b/src/Notifynder/Facades/Notifynder.php new file mode 100644 index 0000000..9296e8d --- /dev/null +++ b/src/Notifynder/Facades/Notifynder.php @@ -0,0 +1,13 @@ + Date: Wed, 13 Jul 2016 07:49:15 -0400 Subject: [PATCH 149/210] Applied fixes from StyleCI --- src/Notifynder/Facades/Notifynder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Facades/Notifynder.php b/src/Notifynder/Facades/Notifynder.php index 9296e8d..0e14d74 100644 --- a/src/Notifynder/Facades/Notifynder.php +++ b/src/Notifynder/Facades/Notifynder.php @@ -10,4 +10,4 @@ protected static function getFacadeAccessor() { return 'notifynder'; } -} \ No newline at end of file +} From 56896e7457660a2c5d8799a78024c3f4bfb3c230 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 13:58:21 +0200 Subject: [PATCH 150/210] fix notification model relations --- src/Notifynder/Models/Notification.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index d6bc955..a7f45cc 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -49,19 +49,19 @@ public function category() public function from() { if (notifynder_config()->isPolymorphic()) { - return $this->belongsTo(notifynder_config()->getModel(), 'from_id'); + return $this->morphTo('from'); } - return $this->morphTo(); + return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'from_id'); } public function to() { if (notifynder_config()->isPolymorphic()) { - return $this->belongsTo(notifynder_config()->getModel(), 'to_id'); + return $this->morphTo('to'); } - return $this->morphTo(); + return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'to_id'); } public function getCustomFillableFields() From 20f924a64098e63bada32df8b6d21e6bf86e794b Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 14:20:30 +0200 Subject: [PATCH 151/210] update translation config --- src/config/notifynder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/config/notifynder.php b/src/config/notifynder.php index 4ad476e..f908d21 100755 --- a/src/config/notifynder.php +++ b/src/config/notifynder.php @@ -47,8 +47,9 @@ * the language you wish to translate ex 'it' or 'italian' and pass as * value an array with the translations */ - 'translations' => [ - + 'translation' => [ + 'enabled' => false, + 'domain' => 'notifynder', ], /* From 696079eeeec62a4241f9350eb7648af417cccc15 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 14:24:19 +0200 Subject: [PATCH 152/210] add template as appended attribute --- src/Notifynder/Models/Notification.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index a7f45cc..0216710 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -24,6 +24,7 @@ class Notification extends Model protected $appends = [ 'text', + 'template_body', ]; protected $casts = [ From 5287d034057c4583eb0142eeb8026ca4028b811e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 14:34:59 +0200 Subject: [PATCH 153/210] add read & unread methods to trait --- src/Notifynder/Models/Notification.php | 4 ++-- src/Notifynder/Traits/Notifable.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 0216710..321a0a5 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -102,12 +102,12 @@ public function getTextAttribute() public function read() { - $this->update(['read' => 1]); + return $this->update(['read' => 1]); } public function unread() { - $this->update(['read' => 0]); + return $this->update(['read' => 0]); } public function resend() diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 9843431..64ee235 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -2,6 +2,8 @@ namespace Fenos\Notifynder\Traits; +use Fenos\Notifynder\Models\Notification; + trait Notifable { public function notifications() @@ -28,4 +30,20 @@ public function sendNotificationTo($category) { return $this->notifynder($category)->to($this); } + + public function readNotification($notification) + { + if(!($notification instanceof Notification)) { + $notification = Notification::firstOrFail($notification); + } + return $notification->read(); + } + + public function unreadNotification($notification) + { + if(!($notification instanceof Notification)) { + $notification = Notification::firstOrFail($notification); + } + return $notification->unread(); + } } From 162efb450d0229857aa7a56cda3056d0a28c8f8f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 13 Jul 2016 08:35:10 -0400 Subject: [PATCH 154/210] Applied fixes from StyleCI --- src/Notifynder/Traits/Notifable.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 64ee235..f934d37 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -33,17 +33,19 @@ public function sendNotificationTo($category) public function readNotification($notification) { - if(!($notification instanceof Notification)) { + if (! ($notification instanceof Notification)) { $notification = Notification::firstOrFail($notification); } + return $notification->read(); } public function unreadNotification($notification) { - if(!($notification instanceof Notification)) { + if (! ($notification instanceof Notification)) { $notification = Notification::firstOrFail($notification); } + return $notification->unread(); } } From 49478eb34143af8f1a3ff57937ab8beea4e66112 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Jul 2016 11:08:19 +0200 Subject: [PATCH 155/210] #105 add methods to set custom fields on the builder and add unittests update codestyle and optimize imports --- src/Notifynder/Builder/Builder.php | 39 +++++++++-- src/Notifynder/Builder/Notification.php | 27 +++++++- src/Notifynder/Collections/Config.php | 14 ++-- src/Notifynder/Helpers/TypeChecker.php | 8 +-- src/Notifynder/Helpers/helpers.php | 8 +-- src/Notifynder/Managers/NotifynderManager.php | 4 +- src/Notifynder/Managers/SenderManager.php | 6 +- src/Notifynder/Models/Notification.php | 6 +- src/Notifynder/NotifynderServiceProvider.php | 32 ++++----- src/Notifynder/Parsers/NotificationParser.php | 2 +- src/Notifynder/Senders/OnceSender.php | 8 +-- src/Notifynder/Traits/Notifable.php | 4 +- tests/integration/Builder/BuilderTest.php | 66 ++++++++++++++++++- 13 files changed, 172 insertions(+), 52 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 40b208e..a697d09 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -2,14 +2,15 @@ namespace Fenos\Notifynder\Builder; -use Closure; +use ArrayAccess; use Carbon\Carbon; +use Closure; use Fenos\Notifynder\Exceptions\UnvalidNotificationException; use Fenos\Notifynder\Helpers\TypeChecker; use Fenos\Notifynder\Models\NotificationCategory; use Illuminate\Database\Eloquent\Model; -class Builder +class Builder implements ArrayAccess { protected $notification; @@ -28,7 +29,7 @@ public function category($category) $categoryId = $category; if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); - } elseif (! is_numeric($category)) { + } elseif (!is_numeric($category)) { $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); } @@ -93,6 +94,16 @@ public function setDates() $this->setNotificationData('created_at', $date); } + public function setField($key, $value) + { + $additionalFields = notifynder_config()->getAdditionalFields(); + if (in_array($key, $additionalFields)) { + $this->setNotificationData($key, $value); + } + + return $this; + } + protected function setEntityData($entity, $property) { if (is_array($entity) && count($entity) == 2) { @@ -122,7 +133,7 @@ protected function setNotificationData($key, $value) public function getNotification() { - if (! $this->notification->isValid()) { + if (!$this->notification->isValid()) { throw new UnvalidNotificationException($this->notification); } @@ -157,4 +168,24 @@ public function loop($data, Closure $callback) return $this; } + + public function offsetExists($offset) + { + return $this->notification->offsetExists($offset); + } + + public function offsetGet($offset) + { + return $this->notification->offsetGet($offset); + } + + public function offsetSet($offset, $value) + { + $this->notification->offsetSet($offset, $value); + } + + public function offsetUnset($offset) + { + $this->notification->offsetUnset($offset); + } } diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index fb37c65..3b7d263 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -2,12 +2,13 @@ namespace Fenos\Notifynder\Builder; -use JsonSerializable; +use ArrayAccess; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Support\Arr; +use JsonSerializable; -class Notification implements Arrayable, Jsonable, JsonSerializable +class Notification implements Arrayable, ArrayAccess, Jsonable, JsonSerializable { protected $attributes = []; @@ -51,7 +52,7 @@ public function set($key, $value) public function isValid() { foreach ($this->requiredFields as $field) { - if (! $this->has($field)) { + if (!$this->has($field)) { return false; } } @@ -90,4 +91,24 @@ public function __toString() { return $this->toJson(); } + + public function offsetExists($offset) + { + return $this->has($offset); + } + + public function offsetGet($offset) + { + return $this->get($offset); + } + + public function offsetSet($offset, $value) + { + $this->set($offset, $value); + } + + public function offsetUnset($offset) + { + Arr::forget($this->attributes, $offset); + } } diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index c552711..41c3ca6 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -12,22 +12,22 @@ class Config implements ConfigContract public function __construct() { - $this->items = app('config')->get('notifynder'); + $this->reload(); } public function isPolymorphic() { - return (bool) $this->get('polymorphic'); + return (bool)$this->get('polymorphic'); } public function isStrict() { - return (bool) $this->get('strict_extra'); + return (bool)$this->get('strict_extra'); } public function isTranslated() { - return (bool) $this->get('translation.enabled'); + return (bool)$this->get('translation.enabled'); } public function getNotificationModel() @@ -77,6 +77,12 @@ public function has($key) public function set($key, $value = null) { Arr::set($this->items, $key, $value); + app('config')->set('notifynder.'.$key, $value); + } + + public function reload() + { + $this->items = app('config')->get('notifynder'); } public function __get($key) diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index a7be1d7..8527c2a 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -2,16 +2,16 @@ namespace Fenos\Notifynder\Helpers; -use Traversable; -use DateTime; use Carbon\Carbon; +use DateTime; use InvalidArgumentException; +use Traversable; class TypeChecker { public function isString($value) { - if (! is_string($value)) { + if (!is_string($value)) { throw new InvalidArgumentException('The value passed must be a string'); } @@ -20,7 +20,7 @@ public function isString($value) public function isNumeric($value) { - if (! is_numeric($value)) { + if (!is_numeric($value)) { throw new InvalidArgumentException('The value passed must be a number'); } diff --git a/src/Notifynder/Helpers/helpers.php b/src/Notifynder/Helpers/helpers.php index d87a2f6..a307984 100644 --- a/src/Notifynder/Helpers/helpers.php +++ b/src/Notifynder/Helpers/helpers.php @@ -1,6 +1,6 @@ {$segment})) { $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { + } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { + } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { $object = $object->getAttribute($segment); } elseif (is_array($object) && array_key_exists($segment, $object)) { $object = array_get($object, $segment, $default); diff --git a/src/Notifynder/Managers/NotifynderManager.php b/src/Notifynder/Managers/NotifynderManager.php index 8267131..34e1191 100755 --- a/src/Notifynder/Managers/NotifynderManager.php +++ b/src/Notifynder/Managers/NotifynderManager.php @@ -2,8 +2,8 @@ namespace Fenos\Notifynder\Managers; -use Closure; use BadMethodCallException; +use Closure; use Fenos\Notifynder\Builder\Builder; use Fenos\Notifynder\Contracts\NotifynderManagerContract; use Fenos\Notifynder\Contracts\SenderManagerContract; @@ -89,7 +89,7 @@ public function __call($name, $arguments) return $this; } - $error = "The method [$name] doesn't exist in the class ".self::class; + $error = "The method [$name] doesn't exist in the class " . self::class; throw new BadMethodCallException($error); } } diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index ebab28b..a0fe721 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -2,9 +2,9 @@ namespace Fenos\Notifynder\Managers; -use Closure; use BadFunctionCallException; use BadMethodCallException; +use Closure; use Fenos\Notifynder\Contracts\SenderContract; use Fenos\Notifynder\Contracts\SenderManagerContract; use Illuminate\Support\Arr; @@ -49,9 +49,9 @@ public function sendWithCustomSender($name, array $notifications) if ($this->hasSender($name)) { $sender = call_user_func_array($this->getSender($name), [$notifications]); if ($sender instanceof SenderContract) { - return (bool) $sender->send($this); + return (bool)$sender->send($this); } - throw new BadFunctionCallException("The sender [{$name}] hasn't returned an instance of ".SenderContract::class); + throw new BadFunctionCallException("The sender [{$name}] hasn't returned an instance of " . SenderContract::class); } throw new BadMethodCallException("The sender [{$name}] isn't registered."); } diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 321a0a5..071e2c4 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -80,7 +80,7 @@ protected function mergeFillables() public function getTemplateBodyAttribute() { if (notifynder_config()->isTranslated()) { - $key = notifynder_config()->getTranslationDomain().'.'.$this->category->name; + $key = notifynder_config()->getTranslationDomain() . '.' . $this->category->name; $trans = trans($key); if ($trans != $key) { return $trans; @@ -92,7 +92,7 @@ public function getTemplateBodyAttribute() public function getTextAttribute() { - if (! array_key_exists('text', $this->attributes)) { + if (!array_key_exists('text', $this->attributes)) { $notifynderParse = new NotificationParser(); $this->attributes['text'] = $notifynderParse->parse($this); } @@ -128,7 +128,7 @@ public function scopeByCategory(Builder $query, $category) $categoryId = $category; if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); - } elseif (! is_numeric($category)) { + } elseif (!is_numeric($category)) { $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index e797099..0e57bc8 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -94,10 +94,10 @@ public function registerSenders() protected function config() { $this->publishes([ - __DIR__.'/../config/notifynder.php' => config_path('notifynder.php'), + __DIR__ . '/../config/notifynder.php' => config_path('notifynder.php'), ]); - $this->mergeConfigFrom(__DIR__.'/../config/notifynder.php', 'notifynder'); + $this->mergeConfigFrom(__DIR__ . '/../config/notifynder.php', 'notifynder'); } /** @@ -105,34 +105,34 @@ protected function config() */ protected function migration() { - if (! class_exists('NotificationCategories')) { + if (!class_exists('NotificationCategories')) { $this->publishMigration('2014_02_10_145728_notification_categories'); } - if (! class_exists('CreateNotificationGroupsTable')) { + if (!class_exists('CreateNotificationGroupsTable')) { $this->publishMigration('2014_08_01_210813_create_notification_groups_table'); } - if (! class_exists('CreateNotificationCategoryNotificationGroupTable')) { + if (!class_exists('CreateNotificationCategoryNotificationGroupTable')) { $this->publishMigration('2014_08_01_211045_create_notification_category_notification_group_table'); } - if (! class_exists('CreateNotificationsTable')) { + if (!class_exists('CreateNotificationsTable')) { $this->publishMigration('2015_05_05_212549_create_notifications_table'); } - if (! class_exists('AddExpireTimeColumnToNotificationTable')) { + if (!class_exists('AddExpireTimeColumnToNotificationTable')) { $this->publishMigration('2015_06_06_211555_add_expire_time_column_to_notification_table'); } - if (! class_exists('ChangeTypeToExtraInNotificationsTable')) { + if (!class_exists('ChangeTypeToExtraInNotificationsTable')) { $this->publishMigration('2015_06_06_211555_change_type_to_extra_in_notifications_table'); } - if (! class_exists('AlterCategoryNameToUnique')) { + if (!class_exists('AlterCategoryNameToUnique')) { $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique'); } - if (! class_exists('MakeNotificationUrlNullable')) { + if (!class_exists('MakeNotificationUrlNullable')) { $this->publishMigration('2016_04_19_200827_make_notification_url_nullable'); } - if (! class_exists('AddStackIdToNotifications')) { + if (!class_exists('AddStackIdToNotifications')) { $this->publishMigration('2016_05_19_144531_add_stack_id_to_notifications'); } - if (! class_exists('UpdateVersion4NotificationsTable')) { + if (!class_exists('UpdateVersion4NotificationsTable')) { $this->publishMigration('2016_07_01_153156_update_version4_notifications_table'); } } @@ -143,8 +143,8 @@ protected function migration() protected function publishMigration($filename) { $extension = '.php'; - $filename = trim($filename, $extension).$extension; - $stub = __DIR__.'/../migrations/'.$filename; + $filename = trim($filename, $extension) . $extension; + $stub = __DIR__ . '/../migrations/' . $filename; $target = $this->migrationFilepath($filename); $this->publishes([$stub => $target], 'migrations'); } @@ -156,9 +156,9 @@ protected function publishMigration($filename) protected function migrationFilepath($filename) { if (function_exists('database_path')) { - return database_path('/migrations/'.$filename); + return database_path('/migrations/' . $filename); } else { - return base_path('/database/migrations/'.$filename); + return base_path('/database/migrations/' . $filename); } } } diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index 435d1da..f098076 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -41,7 +41,7 @@ protected function getValues($body) protected function replace($body, $valueMatch, $replacer) { - $body = str_replace('{'.$replacer.'}', $valueMatch, $body); + $body = str_replace('{' . $replacer . '}', $valueMatch, $body); return $body; } diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 67f92a0..1b02767 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -22,7 +22,7 @@ public function send(SenderManagerContract $sender) $success = true; foreach ($this->notifications as $notification) { $query = $this->getQuery($notification); - if (! $query->exists()) { + if (!$query->exists()) { $success = $sender->send([$notification]) ? $success : false; } else { $query->firstOrFail()->resend(); @@ -41,7 +41,7 @@ protected function getQuery(Notification $notification) ->where('to_id', $notification->to_id) ->where('to_type', $notification->to_type) ->where('category_id', $notification->category_id); - if (isset($notification->extra) && ! empty($notification->extra)) { + if (isset($notification->extra) && !empty($notification->extra)) { $extra = $notification->extra; if (is_array($extra)) { $extra = json_encode($extra); @@ -56,8 +56,8 @@ protected function getQueryInstance() { $model = notifynder_config()->getNotificationModel(); $query = $model::query(); - if (! ($query instanceof EloquentBuilder)) { - throw new BadMethodCallException("The query method hasn't return an instance of [".EloquentBuilder::class.'].'); + if (!($query instanceof EloquentBuilder)) { + throw new BadMethodCallException("The query method hasn't return an instance of [" . EloquentBuilder::class . '].'); } return $query; diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 64ee235..c34ad4e 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -33,7 +33,7 @@ public function sendNotificationTo($category) public function readNotification($notification) { - if(!($notification instanceof Notification)) { + if (!($notification instanceof Notification)) { $notification = Notification::firstOrFail($notification); } return $notification->read(); @@ -41,7 +41,7 @@ public function readNotification($notification) public function unreadNotification($notification) { - if(!($notification instanceof Notification)) { + if (!($notification instanceof Notification)) { $notification = Notification::firstOrFail($notification); } return $notification->unread(); diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php index 30148bf..57904bb 100644 --- a/tests/integration/Builder/BuilderTest.php +++ b/tests/integration/Builder/BuilderTest.php @@ -54,7 +54,7 @@ public function testCreateSingleNotificationWithAll() ->category(1) ->from(1) ->to(2) - ->url('https://google.com') + ->url('http://notifynder.info') ->extra([ 'foo' => 'bar', ]) @@ -63,7 +63,7 @@ public function testCreateSingleNotificationWithAll() $this->assertInstanceOf(Notification::class, $notification); - $this->assertSame('https://google.com', $notification->url); + $this->assertSame('http://notifynder.info', $notification->url); $this->assertInternalType('array', $notification->extra); $this->assertCount(1, $notification->extra); $this->assertSame('bar', $notification->extra['foo']); @@ -145,4 +145,66 @@ public function testCreateMultipleUnvalidNotifications() ->to($data); })->getNotifications(); } + + public function testCreateSingleNotificationWithAdditionalField() + { + notifynder_config()->set('additional_fields.fillable', []); + + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(1) + ->to(2) + ->setField('additional_field', 'value') + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + $this->assertSame(1, $notification->category_id); + $this->assertNull($notification->additional_field); + + notifynder_config()->set('additional_fields.fillable', ['additional_field']); + + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(1) + ->to(2) + ->setField('additional_field', 'value') + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + $this->assertSame(1, $notification->category_id); + $this->assertSame('value', $notification->additional_field); + } + + public function testCreateSingleUnvalidNotificationWithRequiredField() + { + $this->setExpectedException(UnvalidNotificationException::class); + + notifynder_config()->set('additional_fields.required', ['required_field']); + + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(1) + ->to(2) + ->getNotification(); + } + + public function testCreateSingleNotificationWithRequiredField() + { + notifynder_config()->set('additional_fields.required', ['required_field']); + + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(1) + ->to(2) + ->setField('required_field', 'value') + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + $this->assertSame(1, $notification->category_id); + $this->assertSame('value', $notification->required_field); + } } From c3fecf9a27fb48583e311156b0afd85ca99bbd59 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Jul 2016 05:09:26 -0400 Subject: [PATCH 156/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Builder.php | 4 +-- src/Notifynder/Builder/Notification.php | 2 +- src/Notifynder/Collections/Config.php | 6 ++-- src/Notifynder/Helpers/TypeChecker.php | 4 +-- src/Notifynder/Helpers/helpers.php | 8 ++--- src/Notifynder/Managers/NotifynderManager.php | 2 +- src/Notifynder/Managers/SenderManager.php | 4 +-- src/Notifynder/Models/Notification.php | 6 ++-- src/Notifynder/NotifynderServiceProvider.php | 32 +++++++++---------- src/Notifynder/Parsers/NotificationParser.php | 2 +- src/Notifynder/Senders/OnceSender.php | 8 ++--- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index a697d09..090ec4d 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -29,7 +29,7 @@ public function category($category) $categoryId = $category; if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); - } elseif (!is_numeric($category)) { + } elseif (! is_numeric($category)) { $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); } @@ -133,7 +133,7 @@ protected function setNotificationData($key, $value) public function getNotification() { - if (!$this->notification->isValid()) { + if (! $this->notification->isValid()) { throw new UnvalidNotificationException($this->notification); } diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index 3b7d263..4d82980 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -52,7 +52,7 @@ public function set($key, $value) public function isValid() { foreach ($this->requiredFields as $field) { - if (!$this->has($field)) { + if (! $this->has($field)) { return false; } } diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index 41c3ca6..c364592 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -17,17 +17,17 @@ public function __construct() public function isPolymorphic() { - return (bool)$this->get('polymorphic'); + return (bool) $this->get('polymorphic'); } public function isStrict() { - return (bool)$this->get('strict_extra'); + return (bool) $this->get('strict_extra'); } public function isTranslated() { - return (bool)$this->get('translation.enabled'); + return (bool) $this->get('translation.enabled'); } public function getNotificationModel() diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index 8527c2a..27b41dc 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -11,7 +11,7 @@ class TypeChecker { public function isString($value) { - if (!is_string($value)) { + if (! is_string($value)) { throw new InvalidArgumentException('The value passed must be a string'); } @@ -20,7 +20,7 @@ public function isString($value) public function isNumeric($value) { - if (!is_numeric($value)) { + if (! is_numeric($value)) { throw new InvalidArgumentException('The value passed must be a number'); } diff --git a/src/Notifynder/Helpers/helpers.php b/src/Notifynder/Helpers/helpers.php index a307984..d87a2f6 100644 --- a/src/Notifynder/Helpers/helpers.php +++ b/src/Notifynder/Helpers/helpers.php @@ -1,6 +1,6 @@ {$segment})) { $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { + } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { + } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { $object = $object->getAttribute($segment); } elseif (is_array($object) && array_key_exists($segment, $object)) { $object = array_get($object, $segment, $default); diff --git a/src/Notifynder/Managers/NotifynderManager.php b/src/Notifynder/Managers/NotifynderManager.php index 34e1191..63dcd28 100755 --- a/src/Notifynder/Managers/NotifynderManager.php +++ b/src/Notifynder/Managers/NotifynderManager.php @@ -89,7 +89,7 @@ public function __call($name, $arguments) return $this; } - $error = "The method [$name] doesn't exist in the class " . self::class; + $error = "The method [$name] doesn't exist in the class ".self::class; throw new BadMethodCallException($error); } } diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index a0fe721..ed294c3 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -49,9 +49,9 @@ public function sendWithCustomSender($name, array $notifications) if ($this->hasSender($name)) { $sender = call_user_func_array($this->getSender($name), [$notifications]); if ($sender instanceof SenderContract) { - return (bool)$sender->send($this); + return (bool) $sender->send($this); } - throw new BadFunctionCallException("The sender [{$name}] hasn't returned an instance of " . SenderContract::class); + throw new BadFunctionCallException("The sender [{$name}] hasn't returned an instance of ".SenderContract::class); } throw new BadMethodCallException("The sender [{$name}] isn't registered."); } diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 071e2c4..321a0a5 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -80,7 +80,7 @@ protected function mergeFillables() public function getTemplateBodyAttribute() { if (notifynder_config()->isTranslated()) { - $key = notifynder_config()->getTranslationDomain() . '.' . $this->category->name; + $key = notifynder_config()->getTranslationDomain().'.'.$this->category->name; $trans = trans($key); if ($trans != $key) { return $trans; @@ -92,7 +92,7 @@ public function getTemplateBodyAttribute() public function getTextAttribute() { - if (!array_key_exists('text', $this->attributes)) { + if (! array_key_exists('text', $this->attributes)) { $notifynderParse = new NotificationParser(); $this->attributes['text'] = $notifynderParse->parse($this); } @@ -128,7 +128,7 @@ public function scopeByCategory(Builder $query, $category) $categoryId = $category; if ($category instanceof NotificationCategory) { $categoryId = $category->getKey(); - } elseif (!is_numeric($category)) { + } elseif (! is_numeric($category)) { $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 0e57bc8..e797099 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -94,10 +94,10 @@ public function registerSenders() protected function config() { $this->publishes([ - __DIR__ . '/../config/notifynder.php' => config_path('notifynder.php'), + __DIR__.'/../config/notifynder.php' => config_path('notifynder.php'), ]); - $this->mergeConfigFrom(__DIR__ . '/../config/notifynder.php', 'notifynder'); + $this->mergeConfigFrom(__DIR__.'/../config/notifynder.php', 'notifynder'); } /** @@ -105,34 +105,34 @@ protected function config() */ protected function migration() { - if (!class_exists('NotificationCategories')) { + if (! class_exists('NotificationCategories')) { $this->publishMigration('2014_02_10_145728_notification_categories'); } - if (!class_exists('CreateNotificationGroupsTable')) { + if (! class_exists('CreateNotificationGroupsTable')) { $this->publishMigration('2014_08_01_210813_create_notification_groups_table'); } - if (!class_exists('CreateNotificationCategoryNotificationGroupTable')) { + if (! class_exists('CreateNotificationCategoryNotificationGroupTable')) { $this->publishMigration('2014_08_01_211045_create_notification_category_notification_group_table'); } - if (!class_exists('CreateNotificationsTable')) { + if (! class_exists('CreateNotificationsTable')) { $this->publishMigration('2015_05_05_212549_create_notifications_table'); } - if (!class_exists('AddExpireTimeColumnToNotificationTable')) { + if (! class_exists('AddExpireTimeColumnToNotificationTable')) { $this->publishMigration('2015_06_06_211555_add_expire_time_column_to_notification_table'); } - if (!class_exists('ChangeTypeToExtraInNotificationsTable')) { + if (! class_exists('ChangeTypeToExtraInNotificationsTable')) { $this->publishMigration('2015_06_06_211555_change_type_to_extra_in_notifications_table'); } - if (!class_exists('AlterCategoryNameToUnique')) { + if (! class_exists('AlterCategoryNameToUnique')) { $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique'); } - if (!class_exists('MakeNotificationUrlNullable')) { + if (! class_exists('MakeNotificationUrlNullable')) { $this->publishMigration('2016_04_19_200827_make_notification_url_nullable'); } - if (!class_exists('AddStackIdToNotifications')) { + if (! class_exists('AddStackIdToNotifications')) { $this->publishMigration('2016_05_19_144531_add_stack_id_to_notifications'); } - if (!class_exists('UpdateVersion4NotificationsTable')) { + if (! class_exists('UpdateVersion4NotificationsTable')) { $this->publishMigration('2016_07_01_153156_update_version4_notifications_table'); } } @@ -143,8 +143,8 @@ protected function migration() protected function publishMigration($filename) { $extension = '.php'; - $filename = trim($filename, $extension) . $extension; - $stub = __DIR__ . '/../migrations/' . $filename; + $filename = trim($filename, $extension).$extension; + $stub = __DIR__.'/../migrations/'.$filename; $target = $this->migrationFilepath($filename); $this->publishes([$stub => $target], 'migrations'); } @@ -156,9 +156,9 @@ protected function publishMigration($filename) protected function migrationFilepath($filename) { if (function_exists('database_path')) { - return database_path('/migrations/' . $filename); + return database_path('/migrations/'.$filename); } else { - return base_path('/database/migrations/' . $filename); + return base_path('/database/migrations/'.$filename); } } } diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index f098076..435d1da 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -41,7 +41,7 @@ protected function getValues($body) protected function replace($body, $valueMatch, $replacer) { - $body = str_replace('{' . $replacer . '}', $valueMatch, $body); + $body = str_replace('{'.$replacer.'}', $valueMatch, $body); return $body; } diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 1b02767..67f92a0 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -22,7 +22,7 @@ public function send(SenderManagerContract $sender) $success = true; foreach ($this->notifications as $notification) { $query = $this->getQuery($notification); - if (!$query->exists()) { + if (! $query->exists()) { $success = $sender->send([$notification]) ? $success : false; } else { $query->firstOrFail()->resend(); @@ -41,7 +41,7 @@ protected function getQuery(Notification $notification) ->where('to_id', $notification->to_id) ->where('to_type', $notification->to_type) ->where('category_id', $notification->category_id); - if (isset($notification->extra) && !empty($notification->extra)) { + if (isset($notification->extra) && ! empty($notification->extra)) { $extra = $notification->extra; if (is_array($extra)) { $extra = json_encode($extra); @@ -56,8 +56,8 @@ protected function getQueryInstance() { $model = notifynder_config()->getNotificationModel(); $query = $model::query(); - if (!($query instanceof EloquentBuilder)) { - throw new BadMethodCallException("The query method hasn't return an instance of [" . EloquentBuilder::class . '].'); + if (! ($query instanceof EloquentBuilder)) { + throw new BadMethodCallException("The query method hasn't return an instance of [".EloquentBuilder::class.'].'); } return $query; From b25e44a8edf7140cf2005316878978bc775b8186 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Jul 2016 15:59:14 +0200 Subject: [PATCH 157/210] add countUnreadNotifications() --- src/Notifynder/Traits/Notifable.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index f934d37..43d7bb5 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -48,4 +48,9 @@ public function unreadNotification($notification) return $notification->unread(); } + + public function countUnreadNotifications() + { + return $this->notifications()->byRead(0)->count(); + } } From 71a2af2c050a3147144530f49fb45de80b281cd0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Jul 2016 16:11:31 +0200 Subject: [PATCH 158/210] add getNotifications() --- src/Notifynder/Traits/Notifable.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 43d7bb5..315e003 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -53,4 +53,13 @@ public function countUnreadNotifications() { return $this->notifications()->byRead(0)->count(); } + + public function getNotifications($limit = null, $order = 'desc') + { + $query = $this->notifications()->orderBy('created_at', $order); + if(!is_null($limit)) { + $query->limit($limit); + } + return $query->get(); + } } From f60eaa305a33d69e4c573f3c4bbcacd495f1b694 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 19 Jul 2016 10:11:43 -0400 Subject: [PATCH 159/210] Applied fixes from StyleCI --- src/Notifynder/Traits/Notifable.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 315e003..b650a31 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -57,9 +57,10 @@ public function countUnreadNotifications() public function getNotifications($limit = null, $order = 'desc') { $query = $this->notifications()->orderBy('created_at', $order); - if(!is_null($limit)) { + if (! is_null($limit)) { $query->limit($limit); } + return $query->get(); } } From 3b41e162150e8023bf7bf8eaedddaac77b9773ba Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 22 Jul 2016 14:30:50 +0200 Subject: [PATCH 160/210] fix multiple sender add readAllNotifications to trait --- src/Notifynder/Builder/Notification.php | 9 +++++++++ src/Notifynder/Senders/MultipleSender.php | 2 +- src/Notifynder/Traits/Notifable.php | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index 4d82980..dea9f58 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -87,6 +87,15 @@ public function toArray() }, $this->attributes()); } + public function toDbArray() + { + $notification = $this->toArray(); + if(is_array($notification['extra'])) { + $notification['extra'] = json_encode($notification['extra']); + } + return $notification; + } + public function __toString() { return $this->toJson(); diff --git a/src/Notifynder/Senders/MultipleSender.php b/src/Notifynder/Senders/MultipleSender.php index 1f91e4f..24ad3b4 100644 --- a/src/Notifynder/Senders/MultipleSender.php +++ b/src/Notifynder/Senders/MultipleSender.php @@ -27,7 +27,7 @@ public function send(SenderManagerContract $sender) ->table($table) ->max('stack_id') + 1; foreach ($this->notifications as $key => $notification) { - $this->notifications[$key] = $this->notifications[$key]->toArray(); + $this->notifications[$key] = $this->notifications[$key]->toDbArray(); $this->notifications[$key]['stack_id'] = $stackId; } $insert = $this->database diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 315e003..38512eb 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -40,6 +40,11 @@ public function readNotification($notification) return $notification->read(); } + public function readAllNotifications() + { + return $this->notifications()->update(['read' => 1]); + } + public function unreadNotification($notification) { if (! ($notification instanceof Notification)) { From 8e3936399a70313dcc29f66b5418fbc80eb96580 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 22 Jul 2016 08:31:10 -0400 Subject: [PATCH 161/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Notification.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index dea9f58..42be46d 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -90,9 +90,10 @@ public function toArray() public function toDbArray() { $notification = $this->toArray(); - if(is_array($notification['extra'])) { + if (is_array($notification['extra'])) { $notification['extra'] = json_encode($notification['extra']); } + return $notification; } From 80e32b7d01520a976106becf959bac1013e068b0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 22 Jul 2016 14:41:10 +0200 Subject: [PATCH 162/210] fix missing array key --- src/Notifynder/Builder/Notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index dea9f58..9b3cf8b 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -90,7 +90,7 @@ public function toArray() public function toDbArray() { $notification = $this->toArray(); - if(is_array($notification['extra'])) { + if(array_key_exists('extra', $notification) && is_array($notification['extra'])) { $notification['extra'] = json_encode($notification['extra']); } return $notification; From aeec491481ce8503510b4e5e6c106bd5e6d6854c Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 22 Jul 2016 08:41:34 -0400 Subject: [PATCH 163/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Notification.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index 9b3cf8b..ac7e400 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -90,9 +90,10 @@ public function toArray() public function toDbArray() { $notification = $this->toArray(); - if(array_key_exists('extra', $notification) && is_array($notification['extra'])) { + if (array_key_exists('extra', $notification) && is_array($notification['extra'])) { $notification['extra'] = json_encode($notification['extra']); } + return $notification; } From 38fed97903cddaec7040de31980d5519cf2c77ec Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 28 Jul 2016 11:16:37 +0200 Subject: [PATCH 164/210] fix check isNotification --- src/Notifynder/Builder/Builder.php | 17 ++++----- src/Notifynder/Helpers/TypeChecker.php | 50 +++++++++++++++++++------- src/Notifynder/Traits/Notifable.php | 15 +++++--- 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 090ec4d..ab3b47c 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -16,12 +16,9 @@ class Builder implements ArrayAccess protected $notifications = []; - protected $typeChecker; - public function __construct() { $this->notification = new Notification(); - $this->typeChecker = new TypeChecker(); } public function category($category) @@ -64,7 +61,7 @@ public function to() public function url($url) { - $this->typeChecker->isString($url); + TypeChecker::isString($url); $this->setNotificationData('url', $url); return $this; @@ -72,7 +69,7 @@ public function url($url) public function expire($datetime) { - $this->typeChecker->isDate($datetime); + TypeChecker::isDate($datetime); $this->setNotificationData('expires_at', $datetime); return $this; @@ -80,7 +77,7 @@ public function expire($datetime) public function extra(array $extra = []) { - $this->typeChecker->isArray($extra); + TypeChecker::isArray($extra); $this->setNotificationData('extra', $extra); return $this; @@ -107,8 +104,8 @@ public function setField($key, $value) protected function setEntityData($entity, $property) { if (is_array($entity) && count($entity) == 2) { - $this->typeChecker->isString($entity[0]); - $this->typeChecker->isNumeric($entity[1]); + TypeChecker::isString($entity[0]); + TypeChecker::isNumeric($entity[1]); $type = $entity[0]; $id = $entity[1]; @@ -116,7 +113,7 @@ protected function setEntityData($entity, $property) $type = $entity[0]->getMorphClass(); $id = $entity[0]->getKey(); } else { - $this->typeChecker->isNumeric($entity[0]); + TypeChecker::isNumeric($entity[0]); $type = notifynder_config()->getNotifiedModel(); $id = $entity[0]; @@ -158,7 +155,7 @@ public function getNotifications() public function loop($data, Closure $callback) { - $this->typeChecker->isIterable($data); + TypeChecker::isIterable($data); foreach ($data as $key => $value) { $builder = new static(); diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index 27b41dc..fde9cac 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -9,48 +9,74 @@ class TypeChecker { - public function isString($value) + public static function isString($value, $strict = true) { - if (! is_string($value)) { - throw new InvalidArgumentException('The value passed must be a string'); + if (!is_string($value)) { + if ($strict) { + throw new InvalidArgumentException('The value passed must be a string'); + } + return false; } return true; } - public function isNumeric($value) + public static function isNumeric($value, $strict = true) { - if (! is_numeric($value)) { - throw new InvalidArgumentException('The value passed must be a number'); + if (!is_numeric($value)) { + if ($strict) { + throw new InvalidArgumentException('The value passed must be a number'); + } + return false; } return true; } - public function isDate($value) + public static function isDate($value, $strict = true) { if ($value instanceof Carbon || $value instanceof DateTime) { return true; } - throw new InvalidArgumentException('The value passed must be an instance of Carbon\\Carbon or DateTime'); + if ($strict) { + throw new InvalidArgumentException('The value passed must be an instance of Carbon\\Carbon or DateTime'); + } + return false; } - public function isArray($value) + public static function isArray($value, $strict = true) { if (is_array($value) && count($value) > 0) { return true; } - throw new InvalidArgumentException('The value passed must be an array'); + if ($strict) { + throw new InvalidArgumentException('The value passed must be an array'); + } + return false; } - public function isIterable($value) + public static function isIterable($value, $strict = true) { if ((is_array($value) || $value instanceof Traversable) && count($value) > 0) { return true; } - throw new InvalidArgumentException('The value passed must be iterable'); + if ($strict) { + throw new InvalidArgumentException('The value passed must be iterable'); + } + return false; + } + + public static function isNotification($notification, $strict = true) + { + if (!is_a($notification, notifynder_config()->getNotificationModel())) { + if ($strict) { + throw new InvalidArgumentException('The value passed must be an Notification Model instance'); + } + return false; + } + return true; } } diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index b2f037a..bf13ede 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -2,6 +2,7 @@ namespace Fenos\Notifynder\Traits; +use Fenos\Notifynder\Helpers\TypeChecker; use Fenos\Notifynder\Models\Notification; trait Notifable @@ -33,11 +34,14 @@ public function sendNotificationTo($category) public function readNotification($notification) { - if (! ($notification instanceof Notification)) { + if (!TypeChecker::isNotification($notification, false)) { $notification = Notification::firstOrFail($notification); } - return $notification->read(); + if($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { + return $notification->read(); + } + return false; } public function readAllNotifications() @@ -47,11 +51,14 @@ public function readAllNotifications() public function unreadNotification($notification) { - if (! ($notification instanceof Notification)) { + if (!TypeChecker::isNotification($notification, false)) { $notification = Notification::firstOrFail($notification); } - return $notification->unread(); + if($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { + return $notification->unread(); + } + return false; } public function countUnreadNotifications() From f7aa5fdaaf6e5a1c0bf82e9ea3fb908b171ab926 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 28 Jul 2016 05:16:55 -0400 Subject: [PATCH 165/210] Applied fixes from StyleCI --- src/Notifynder/Helpers/TypeChecker.php | 13 ++++++++++--- src/Notifynder/Traits/Notifable.php | 10 ++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index fde9cac..098dd69 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -11,10 +11,11 @@ class TypeChecker { public static function isString($value, $strict = true) { - if (!is_string($value)) { + if (! is_string($value)) { if ($strict) { throw new InvalidArgumentException('The value passed must be a string'); } + return false; } @@ -23,10 +24,11 @@ public static function isString($value, $strict = true) public static function isNumeric($value, $strict = true) { - if (!is_numeric($value)) { + if (! is_numeric($value)) { if ($strict) { throw new InvalidArgumentException('The value passed must be a number'); } + return false; } @@ -42,6 +44,7 @@ public static function isDate($value, $strict = true) if ($strict) { throw new InvalidArgumentException('The value passed must be an instance of Carbon\\Carbon or DateTime'); } + return false; } @@ -54,6 +57,7 @@ public static function isArray($value, $strict = true) if ($strict) { throw new InvalidArgumentException('The value passed must be an array'); } + return false; } @@ -66,17 +70,20 @@ public static function isIterable($value, $strict = true) if ($strict) { throw new InvalidArgumentException('The value passed must be iterable'); } + return false; } public static function isNotification($notification, $strict = true) { - if (!is_a($notification, notifynder_config()->getNotificationModel())) { + if (! is_a($notification, notifynder_config()->getNotificationModel())) { if ($strict) { throw new InvalidArgumentException('The value passed must be an Notification Model instance'); } + return false; } + return true; } } diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index bf13ede..11d7b4f 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -34,13 +34,14 @@ public function sendNotificationTo($category) public function readNotification($notification) { - if (!TypeChecker::isNotification($notification, false)) { + if (! TypeChecker::isNotification($notification, false)) { $notification = Notification::firstOrFail($notification); } - if($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { + if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { return $notification->read(); } + return false; } @@ -51,13 +52,14 @@ public function readAllNotifications() public function unreadNotification($notification) { - if (!TypeChecker::isNotification($notification, false)) { + if (! TypeChecker::isNotification($notification, false)) { $notification = Notification::firstOrFail($notification); } - if($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { + if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { return $notification->unread(); } + return false; } From c55f2fb49548a088c8aeb29c3b389fee3c310a4e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 12:02:11 +0200 Subject: [PATCH 166/210] add php doc blocks to all classes --- .gitignore | 3 +- .travis.yml | 2 +- phpunit.xml | 3 +- src/Notifynder/Builder/Builder.php | 91 ++++++++++++++++++- src/Notifynder/Builder/Notification.php | 76 ++++++++++++++++ src/Notifynder/Collections/Config.php | 62 ++++++++++++- src/Notifynder/Contracts/ConfigContract.php | 51 +++++++++++ .../Contracts/NotifynderManagerContract.php | 30 +++++- src/Notifynder/Contracts/SenderContract.php | 13 +++ .../Contracts/SenderManagerContract.php | 26 ++++++ src/Notifynder/Helpers/TypeChecker.php | 40 ++++++++ src/Notifynder/Helpers/helpers.php | 6 ++ src/Notifynder/Managers/NotifynderManager.php | 54 ++++++++++- src/Notifynder/Managers/SenderManager.php | 43 ++++++++- src/Notifynder/Models/Notification.php | 62 +++++++++++++ .../Models/NotificationCategory.php | 24 +++++ src/Notifynder/Models/NotificationGroup.php | 13 +++ src/Notifynder/NotifynderServiceProvider.php | 48 ++++++++-- src/Notifynder/Parsers/NotificationParser.php | 30 +++++- src/Notifynder/Senders/MultipleSender.php | 23 ++++- src/Notifynder/Senders/OnceSender.php | 27 ++++++ src/Notifynder/Senders/SingleSender.php | 18 ++++ src/Notifynder/Traits/Notifable.php | 71 ++++++++++++++- 23 files changed, 791 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index dfd6caa..74333e2 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor -composer.lock \ No newline at end of file +composer.lock +/build \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 5796ba3..40b0a9f 100755 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ before_script: script: ## - vendor/bin/phpspec run - vendor/bin/phpunit -## - php CoverageChecker.php clover.xml 65 +## - php CoverageChecker.php ./build/logs/clover.xml 65 ## Send Build Notifications to Slack notifications: diff --git a/phpunit.xml b/phpunit.xml index b75df8f..27329c7 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -20,7 +20,8 @@ - + + diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index ab3b47c..06d6a9f 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -10,17 +10,34 @@ use Fenos\Notifynder\Models\NotificationCategory; use Illuminate\Database\Eloquent\Model; +/** + * Class Builder + * @package Fenos\Notifynder\Builder + */ class Builder implements ArrayAccess { + /** + * @var Notification + */ protected $notification; + /** + * @var array + */ protected $notifications = []; + /** + * Builder constructor. + */ public function __construct() { $this->notification = new Notification(); } + /** + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return $this + */ public function category($category) { $categoryId = $category; @@ -35,6 +52,9 @@ public function category($category) return $this; } + /** + * @return $this + */ public function from() { $args = func_get_args(); @@ -43,6 +63,9 @@ public function from() return $this; } + /** + * @return $this + */ public function anonymous() { $this->setNotificationData('from_type', null); @@ -51,6 +74,9 @@ public function anonymous() return $this; } + /** + * @return $this + */ public function to() { $args = func_get_args(); @@ -59,6 +85,10 @@ public function to() return $this; } + /** + * @param string $url + * @return $this + */ public function url($url) { TypeChecker::isString($url); @@ -67,14 +97,23 @@ public function url($url) return $this; } + /** + * @param Carbon|\DateTime $datetime + * @return $this + */ public function expire($datetime) { TypeChecker::isDate($datetime); - $this->setNotificationData('expires_at', $datetime); + $carbon = new Carbon($datetime); + $this->setNotificationData('expires_at', $carbon); return $this; } + /** + * @param array $extra + * @return $this + */ public function extra(array $extra = []) { TypeChecker::isArray($extra); @@ -83,6 +122,9 @@ public function extra(array $extra = []) return $this; } + /** + * Set updated_at and created_at fields. + */ public function setDates() { $date = Carbon::now(); @@ -91,6 +133,13 @@ public function setDates() $this->setNotificationData('created_at', $date); } + /** + * Set a single field value. + * + * @param string $key + * @param mixed $value + * @return $this + */ public function setField($key, $value) { $additionalFields = notifynder_config()->getAdditionalFields(); @@ -101,6 +150,10 @@ public function setField($key, $value) return $this; } + /** + * @param array $entity + * @param string $property + */ protected function setEntityData($entity, $property) { if (is_array($entity) && count($entity) == 2) { @@ -123,11 +176,19 @@ protected function setEntityData($entity, $property) $this->setNotificationData("{$property}_id", $id); } + /** + * @param string $key + * @param mixed $value + */ protected function setNotificationData($key, $value) { $this->notification->set($key, $value); } + /** + * @return Notification + * @throws UnvalidNotificationException + */ public function getNotification() { if (! $this->notification->isValid()) { @@ -139,11 +200,18 @@ public function getNotification() return $this->notification; } + /** + * @param Notification $notification + */ public function addNotification(Notification $notification) { $this->notifications[] = $notification; } + /** + * @return array + * @throws UnvalidNotificationException + */ public function getNotifications() { if (count($this->notifications) == 0) { @@ -153,6 +221,12 @@ public function getNotifications() return $this->notifications; } + /** + * @param array|\Traversable $data + * @param Closure $callback + * @return $this + * @throws UnvalidNotificationException + */ public function loop($data, Closure $callback) { TypeChecker::isIterable($data); @@ -166,21 +240,36 @@ public function loop($data, Closure $callback) return $this; } + /** + * @param string $offset + * @return bool + */ public function offsetExists($offset) { return $this->notification->offsetExists($offset); } + /** + * @param string $offset + * @return mixed + */ public function offsetGet($offset) { return $this->notification->offsetGet($offset); } + /** + * @param string $offset + * @param mixed $value + */ public function offsetSet($offset, $value) { $this->notification->offsetSet($offset, $value); } + /** + * @param string $offset + */ public function offsetUnset($offset) { $this->notification->offsetUnset($offset); diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index ac7e400..12e60ed 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -8,47 +8,84 @@ use Illuminate\Support\Arr; use JsonSerializable; +/** + * Class Notification + * @package Fenos\Notifynder\Builder + */ class Notification implements Arrayable, ArrayAccess, Jsonable, JsonSerializable { + /** + * @var array + */ protected $attributes = []; + /** + * @var array + */ protected $requiredFields = [ 'from_id', 'to_id', 'category_id', ]; + /** + * Notification constructor. + */ public function __construct() { $customRequired = notifynder_config()->getAdditionalRequiredFields(); $this->requiredFields = array_merge($this->requiredFields, $customRequired); } + /** + * @return array + */ public function attributes() { return $this->attributes; } + /** + * @param string $key + * @param null|mixed $default + * @return mixed + */ public function attribute($key, $default = null) { return $this->get($key, $default); } + /** + * @param string $key + * @return bool + */ public function has($key) { return Arr::has($this->attributes, $key); } + /** + * @param string $key + * @param null|mixed $default + * @return mixed + */ public function get($key, $default = null) { return Arr::get($this->attributes, $key, $default); } + /** + * @param string $key + * @param mixed $value + */ public function set($key, $value) { Arr::set($this->attributes, $key, $value); } + /** + * @return bool + */ public function isValid() { foreach ($this->requiredFields as $field) { @@ -60,26 +97,44 @@ public function isValid() return true; } + /** + * @param string $key + * @return mixed + */ public function __get($key) { return $this->get($key); } + /** + * @param string $key + * @param mixed $value + */ public function __set($key, $value) { $this->set($key, $value); } + /** + * @param int $options + * @return string + */ public function toJson($options = 0) { return json_encode($this->jsonSerialize(), $options); } + /** + * @return array + */ public function jsonSerialize() { return $this->toArray(); } + /** + * @return array + */ public function toArray() { return array_map(function ($value) { @@ -87,6 +142,9 @@ public function toArray() }, $this->attributes()); } + /** + * @return array + */ public function toDbArray() { $notification = $this->toArray(); @@ -97,26 +155,44 @@ public function toDbArray() return $notification; } + /** + * @return string + */ public function __toString() { return $this->toJson(); } + /** + * @param string $offset + * @return bool + */ public function offsetExists($offset) { return $this->has($offset); } + /** + * @param string $offset + * @return mixed + */ public function offsetGet($offset) { return $this->get($offset); } + /** + * @param string $offset + * @param mixed $value + */ public function offsetSet($offset, $value) { $this->set($offset, $value); } + /** + * @param string $offset + */ public function offsetUnset($offset) { Arr::forget($this->attributes, $offset); diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index c364592..c31ad8b 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -5,31 +5,54 @@ use Fenos\Notifynder\Contracts\ConfigContract; use Fenos\Notifynder\Models\Notification; use Illuminate\Support\Arr; +use InvalidArgumentException; +/** + * Class Config + * @package Fenos\Notifynder\Collections + */ class Config implements ConfigContract { + /** + * @var array + */ protected $items; + /** + * Config constructor. + */ public function __construct() { $this->reload(); } + /** + * @return bool + */ public function isPolymorphic() { return (bool) $this->get('polymorphic'); } + /** + * @return bool + */ public function isStrict() { return (bool) $this->get('strict_extra'); } + /** + * @return bool + */ public function isTranslated() { return (bool) $this->get('translation.enabled'); } + /** + * @return string + */ public function getNotificationModel() { $class = $this->get('notification_model'); @@ -40,56 +63,93 @@ public function getNotificationModel() return Notification::class; } + /** + * @return string + * @throws InvalidArgumentException + */ public function getNotifiedModel() { $class = $this->get('model'); if (class_exists($class)) { return $class; } - throw new \InvalidArgumentException("The model class [{$class}] doesn't exist."); + throw new InvalidArgumentException("The model class [{$class}] doesn't exist."); } + /** + * @return array + */ public function getAdditionalFields() { return Arr::flatten($this->get('additional_fields', [])); } + /** + * @return array + */ public function getAdditionalRequiredFields() { return Arr::flatten($this->get('additional_fields.required', [])); } + /** + * @return string + */ public function getTranslationDomain() { return $this->get('translation.domain', 'notifynder'); } + /** + * @param string $key + * @param null|mixed $default + * @return mixed + */ public function get($key, $default = null) { return Arr::get($this->items, $key, $default); } + /** + * @param string $key + * @return bool + */ public function has($key) { return Arr::has($this->items, $key); } + /** + * @param string $key + * @param null|mixed $value + */ public function set($key, $value = null) { Arr::set($this->items, $key, $value); app('config')->set('notifynder.'.$key, $value); } + /** + * + */ public function reload() { $this->items = app('config')->get('notifynder'); } + /** + * @param string $key + * @return mixed + */ public function __get($key) { return $this->get($key); } + /** + * @param string $key + * @param mixed $value + */ public function __set($key, $value) { $this->set($key, $value); diff --git a/src/Notifynder/Contracts/ConfigContract.php b/src/Notifynder/Contracts/ConfigContract.php index 35ede10..64de064 100644 --- a/src/Notifynder/Contracts/ConfigContract.php +++ b/src/Notifynder/Contracts/ConfigContract.php @@ -2,31 +2,82 @@ namespace Fenos\Notifynder\Contracts; +/** + * Interface ConfigContract + * @package Fenos\Notifynder\Contracts + */ interface ConfigContract { + /** + * @return bool + */ public function isPolymorphic(); + /** + * @return bool + */ public function isStrict(); + /** + * @return bool + */ public function isTranslated(); + /** + * @return string + */ public function getNotificationModel(); + /** + * @return string + */ public function getNotifiedModel(); + /** + * @return array + */ public function getAdditionalFields(); + /** + * @return array + */ public function getAdditionalRequiredFields(); + /** + * @return string + */ public function getTranslationDomain(); + /** + * @param string $key + * @param mixed $default + * @return mixed + */ public function get($key, $default); + /** + * @param string $key + * @return bool + */ public function has($key); + /** + * @param string $key + * @param mixed $value + * @return mixed + */ public function set($key, $value); + /** + * @param string $key + * @return mixed + */ public function __get($key); + /** + * @param string $key + * @param mixed $value + * @return mixed + */ public function __set($key, $value); } diff --git a/src/Notifynder/Contracts/NotifynderManagerContract.php b/src/Notifynder/Contracts/NotifynderManagerContract.php index 694e282..11dd105 100755 --- a/src/Notifynder/Contracts/NotifynderManagerContract.php +++ b/src/Notifynder/Contracts/NotifynderManagerContract.php @@ -6,11 +6,39 @@ interface NotifynderManagerContract { + /** + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return $this + */ public function category($category); + /** + * @param array|\Traversable $data + * @param Closure $callback + * @return $this + */ public function loop($data, Closure $callback); + /** + * @return bool + */ public function send(); - public function builder(); + /** + * @param bool $force + * @return \Fenos\Notifynder\Builder\Builder + */ + public function builder($force = false); + + /** + * @return SenderManagerContract + */ + public function sender(); + + /** + * @param string $name + * @param Closure $sender + * @return bool + */ + public function extend($name, Closure $sender); } diff --git a/src/Notifynder/Contracts/SenderContract.php b/src/Notifynder/Contracts/SenderContract.php index 3cd4b82..1021fe4 100644 --- a/src/Notifynder/Contracts/SenderContract.php +++ b/src/Notifynder/Contracts/SenderContract.php @@ -2,9 +2,22 @@ namespace Fenos\Notifynder\Contracts; +/** + * Interface SenderContract + * @package Fenos\Notifynder\Contracts + */ interface SenderContract { + /** + * SenderContract constructor. + * + * @param array $notifications + */ public function __construct(array $notifications); + /** + * @param SenderManagerContract $sender + * @return bool + */ public function send(SenderManagerContract $sender); } diff --git a/src/Notifynder/Contracts/SenderManagerContract.php b/src/Notifynder/Contracts/SenderManagerContract.php index b50cc16..945325f 100644 --- a/src/Notifynder/Contracts/SenderManagerContract.php +++ b/src/Notifynder/Contracts/SenderManagerContract.php @@ -4,15 +4,41 @@ use Closure; +/** + * Interface SenderManagerContract + * @package Fenos\Notifynder\Contracts + */ interface SenderManagerContract { + /** + * @param array $notifications + * @return bool + */ public function send(array $notifications); + /** + * @param string $name + * @return bool + */ public function hasSender($name); + /** + * @param string $name + * @return Closure + */ public function getSender($name); + /** + * @param string $name + * @param Closure $sender + * @return bool + */ public function extend($name, Closure $sender); + /** + * @param string $name + * @param array $notifications + * @return bool + */ public function sendWithCustomSender($name, array $notifications); } diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index 098dd69..14c4722 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -7,8 +7,18 @@ use InvalidArgumentException; use Traversable; +/** + * Class TypeChecker + * @package Fenos\Notifynder\Helpers + */ class TypeChecker { + /** + * @param $value + * @param bool $strict + * @return bool + * @throws InvalidArgumentException + */ public static function isString($value, $strict = true) { if (! is_string($value)) { @@ -22,6 +32,12 @@ public static function isString($value, $strict = true) return true; } + /** + * @param $value + * @param bool $strict + * @return bool + * @throws InvalidArgumentException + */ public static function isNumeric($value, $strict = true) { if (! is_numeric($value)) { @@ -35,6 +51,12 @@ public static function isNumeric($value, $strict = true) return true; } + /** + * @param $value + * @param bool $strict + * @return bool + * @throws InvalidArgumentException + */ public static function isDate($value, $strict = true) { if ($value instanceof Carbon || $value instanceof DateTime) { @@ -48,6 +70,12 @@ public static function isDate($value, $strict = true) return false; } + /** + * @param $value + * @param bool $strict + * @return bool + * @throws InvalidArgumentException + */ public static function isArray($value, $strict = true) { if (is_array($value) && count($value) > 0) { @@ -61,6 +89,12 @@ public static function isArray($value, $strict = true) return false; } + /** + * @param $value + * @param bool $strict + * @return bool + * @throws InvalidArgumentException + */ public static function isIterable($value, $strict = true) { if ((is_array($value) || $value instanceof Traversable) && count($value) > 0) { @@ -74,6 +108,12 @@ public static function isIterable($value, $strict = true) return false; } + /** + * @param $notification + * @param bool $strict + * @return bool + * @throws InvalidArgumentException + */ public static function isNotification($notification, $strict = true) { if (! is_a($notification, notifynder_config()->getNotificationModel())) { diff --git a/src/Notifynder/Helpers/helpers.php b/src/Notifynder/Helpers/helpers.php index d87a2f6..0ffba4b 100644 --- a/src/Notifynder/Helpers/helpers.php +++ b/src/Notifynder/Helpers/helpers.php @@ -18,6 +18,12 @@ function notifynder_config($key = null, $default = null) } if (! function_exists('notifynder_mixed_get')) { + /** + * @param array|object $object + * @param string $key + * @param null|mixed $default + * @return mixed + */ function notifynder_mixed_get($object, $key, $default = null) { if (is_null($key) || trim($key) == '') { diff --git a/src/Notifynder/Managers/NotifynderManager.php b/src/Notifynder/Managers/NotifynderManager.php index 63dcd28..3f4d823 100755 --- a/src/Notifynder/Managers/NotifynderManager.php +++ b/src/Notifynder/Managers/NotifynderManager.php @@ -9,6 +9,10 @@ use Fenos\Notifynder\Contracts\SenderManagerContract; use Illuminate\Support\Str; +/** + * Class NotifynderManager + * @package Fenos\Notifynder\Managers + */ class NotifynderManager implements NotifynderManagerContract { /** @@ -16,13 +20,24 @@ class NotifynderManager implements NotifynderManagerContract */ protected $builder; + /** + * @var SenderManagerContract + */ protected $sender; + /** + * NotifynderManager constructor. + * @param SenderManagerContract $sender + */ public function __construct(SenderManagerContract $sender) { $this->sender = $sender; } + /** + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return $this + */ public function category($category) { $this->builder(true); @@ -31,6 +46,11 @@ public function category($category) return $this; } + /** + * @param array|\Traversable $data + * @param Closure $callback + * @return $this + */ public function loop($data, Closure $callback) { $this->builder(true); @@ -39,45 +59,69 @@ public function loop($data, Closure $callback) return $this; } - public function builder($new = false) + /** + * @param bool $force + * @return Builder + */ + public function builder($force = false) { - if (is_null($this->builder) || $new) { + if (is_null($this->builder) || $force) { $this->builder = new Builder(); } return $this->builder; } + /** + * @return bool + */ public function send() { $sent = $this->sender->send($this->builder->getNotifications()); $this->reset(); - return $sent; + return (bool) $sent; } + /** + * @return SenderManagerContract + */ public function sender() { return $this->sender; } + /** + * + */ protected function reset() { $this->builder = null; } + /** + * @param string $name + * @param Closure $sender + * @return bool + */ public function extend($name, Closure $sender) { - return $this->sender->extend($name, $sender); + return (bool) $this->sender->extend($name, $sender); } + /** + * @param $name + * @param $arguments + * @return $this|bool + * @throws BadMethodCallException + */ public function __call($name, $arguments) { if (Str::startsWith($name, 'send')) { $sent = $this->sender->sendWithCustomSender($name, $this->builder->getNotifications()); $this->reset(); - return $sent; + return (bool) $sent; } if ($this->builder instanceof Builder && method_exists($this->builder, $name)) { diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index ed294c3..1fb63eb 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -10,29 +10,53 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; +/** + * Class SenderManager + * @package Fenos\Notifynder\Managers + */ class SenderManager implements SenderManagerContract { + /** + * @var array + */ protected $senders = []; + /** + * @param array $notifications + * @return bool + */ public function send(array $notifications) { if (count($notifications) == 1) { - return $this->sendSingle($notifications); + return (bool) $this->sendSingle($notifications); } - return $this->sendMultiple($notifications); + return (bool) $this->sendMultiple($notifications); } + /** + * @param string $name + * @return bool + */ public function hasSender($name) { return Arr::has($this->senders, $name); } + /** + * @param string $name + * @return Closure + */ public function getSender($name) { return Arr::get($this->senders, $name); } + /** + * @param string $name + * @param Closure $sender + * @return bool + */ public function extend($name, Closure $sender) { if (Str::startsWith($name, 'send')) { @@ -44,6 +68,13 @@ public function extend($name, Closure $sender) return false; } + /** + * @param string $name + * @param array $notifications + * @return bool + * @throws BadFunctionCallException + * @throws BadMethodCallException + */ public function sendWithCustomSender($name, array $notifications) { if ($this->hasSender($name)) { @@ -56,7 +87,13 @@ public function sendWithCustomSender($name, array $notifications) throw new BadMethodCallException("The sender [{$name}] isn't registered."); } - public function __call($name, $arguments) + /** + * @param string $name + * @param array $arguments + * @return bool + * @throws BadMethodCallException + */ + public function __call($name, array $arguments) { if (isset($arguments[0]) && is_array($arguments[0])) { return $this->sendWithCustomSender($name, $arguments[0]); diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 321a0a5..a830817 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -7,8 +7,15 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Class Notification + * @package Fenos\Notifynder\Models + */ class Notification extends Model { + /** + * @var array + */ protected $fillable = [ 'to_id', 'to_type', @@ -22,15 +29,26 @@ class Notification extends Model 'stack_id', ]; + /** + * @var array + */ protected $appends = [ 'text', 'template_body', ]; + /** + * @var array + */ protected $casts = [ 'extra' => 'array', ]; + /** + * Notification constructor. + * + * @param array $attributes + */ public function __construct($attributes = []) { $this->fillable($this->mergeFillables()); @@ -42,11 +60,17 @@ public function __construct($attributes = []) parent::__construct($attributes); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function category() { return $this->belongsTo(NotificationCategory::class, 'category_id'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo + */ public function from() { if (notifynder_config()->isPolymorphic()) { @@ -56,6 +80,9 @@ public function from() return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'from_id'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\MorphTo + */ public function to() { if (notifynder_config()->isPolymorphic()) { @@ -65,11 +92,17 @@ public function to() return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'to_id'); } + /** + * @return array + */ public function getCustomFillableFields() { return notifynder_config()->getAdditionalFields(); } + /** + * @return array + */ protected function mergeFillables() { $fillables = array_unique($this->getFillable() + $this->getCustomFillableFields()); @@ -77,6 +110,9 @@ protected function mergeFillables() return $fillables; } + /** + * @return string + */ public function getTemplateBodyAttribute() { if (notifynder_config()->isTranslated()) { @@ -90,6 +126,10 @@ public function getTemplateBodyAttribute() return $this->category->text; } + /** + * @return string + * @throws \Fenos\Notifynder\Exceptions\ExtraParamsException + */ public function getTextAttribute() { if (! array_key_exists('text', $this->attributes)) { @@ -100,16 +140,25 @@ public function getTextAttribute() return $this->attributes['text']; } + /** + * @return bool|int + */ public function read() { return $this->update(['read' => 1]); } + /** + * @return bool|int + */ public function unread() { return $this->update(['read' => 0]); } + /** + * @return bool + */ public function resend() { $this->updateTimestamps(); @@ -118,11 +167,19 @@ public function resend() return $this->save(); } + /** + * @return bool + */ public function isAnonymous() { return is_null($this->from_id); } + /** + * @param Builder $query + * @param $category + * @return Builder + */ public function scopeByCategory(Builder $query, $category) { $categoryId = $category; @@ -135,6 +192,11 @@ public function scopeByCategory(Builder $query, $category) return $query->where('category_id', $categoryId); } + /** + * @param Builder $query + * @param int $read + * @return Builder + */ public function scopeByRead(Builder $query, $read = 1) { return $query->where('read', $read); diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 13f13db..2bbdeb7 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -5,14 +5,30 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Class NotificationCategory + * @package Fenos\Notifynder\Models + */ class NotificationCategory extends Model { + /** + * @var string + */ protected $table = 'notification_categories'; + /** + * @var array + */ protected $fillable = ['name', 'text']; + /** + * @var bool + */ public $timestamps = false; + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function notifications() { $config = app('notifynder.config'); @@ -21,6 +37,9 @@ public function notifications() return $this->hasMany($model, 'category_id'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ public function categories() { return $this->belongsToMany( @@ -31,6 +50,11 @@ public function categories() ); } + /** + * @param Builder $query + * @param $name + * @return Builder + */ public function scopeByName(Builder $query, $name) { return $query->where('name', $name); diff --git a/src/Notifynder/Models/NotificationGroup.php b/src/Notifynder/Models/NotificationGroup.php index 9abccfc..6fd514e 100755 --- a/src/Notifynder/Models/NotificationGroup.php +++ b/src/Notifynder/Models/NotificationGroup.php @@ -4,12 +4,25 @@ use Illuminate\Database\Eloquent\Model; +/** + * Class NotificationGroup + * @package Fenos\Notifynder\Models + */ class NotificationGroup extends Model { + /** + * @var array + */ protected $fillable = ['name']; + /** + * @var bool + */ public $timestamps = false; + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ public function categories() { return $this->belongsToMany( diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index e797099..e21a2dc 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -13,8 +13,17 @@ use Fenos\Notifynder\Senders\SingleSender; use Illuminate\Support\ServiceProvider; +/** + * Class NotifynderServiceProvider + * @package Fenos\Notifynder + */ class NotifynderServiceProvider extends ServiceProvider { + /** + * Register the service provider. + * + * @return void + */ public function register() { $this->bindContracts(); @@ -25,6 +34,11 @@ public function register() $this->registerSenders(); } + /** + * Boot the service provider. + * + * @return void + */ public function boot() { $this->config(); @@ -33,6 +47,8 @@ public function boot() /** * Bind contracts. + * + * @return void */ protected function bindContracts() { @@ -42,7 +58,9 @@ protected function bindContracts() } /** - * Bind notifynder config. + * Bind Notifynder config. + * + * @return void */ protected function bindConfig() { @@ -52,7 +70,9 @@ protected function bindConfig() } /** - * Bind notifynder config. + * Bind Notifynder sender. + * + * @return void */ protected function bindSender() { @@ -62,7 +82,9 @@ protected function bindSender() } /** - * Bind notifynder manager. + * Bind Notifynder manager. + * + * @return void */ protected function bindNotifynder() { @@ -73,6 +95,11 @@ protected function bindNotifynder() }); } + /** + * Register the default senders. + * + * @return void + */ public function registerSenders() { app('notifynder')->extend('sendSingle', function (array $notifications) { @@ -89,7 +116,9 @@ public function registerSenders() } /** - * Publish config file. + * Publish and merge config file. + * + * @return void */ protected function config() { @@ -102,6 +131,8 @@ protected function config() /** * Publish migration files. + * + * @return void */ protected function migration() { @@ -138,22 +169,27 @@ protected function migration() } /** + * Publish a single migration file. + * * @param string $filename + * @return void */ protected function publishMigration($filename) { $extension = '.php'; $filename = trim($filename, $extension).$extension; $stub = __DIR__.'/../migrations/'.$filename; - $target = $this->migrationFilepath($filename); + $target = $this->getMigrationFilepath($filename); $this->publishes([$stub => $target], 'migrations'); } /** + * Get the migration file path. + * * @param string $filename * @return string */ - protected function migrationFilepath($filename) + protected function getMigrationFilepath($filename) { if (function_exists('database_path')) { return database_path('/migrations/'.$filename); diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index 435d1da..43822fd 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -5,10 +5,24 @@ use Fenos\Notifynder\Exceptions\ExtraParamsException; use Fenos\Notifynder\Models\Notification; +/** + * Class NotificationParser + * @package Fenos\Notifynder\Parsers + */ class NotificationParser { - const RULE = '/\{(.+?)(?:\{(.+)\})?\}/'; + /** + * Regex-search-rule + */ + const RULE = '/\{([a-zA-Z0-9_\.]+)\}/m'; + /** + * Parse a notification and return the body text. + * + * @param Notification $notification + * @return string + * @throws ExtraParamsException + */ public function parse(Notification $notification) { $text = $notification->template_body; @@ -31,6 +45,12 @@ public function parse(Notification $notification) return $text; } + /** + * Get an array of all placehodlers. + * + * @param string $body + * @return array + */ protected function getValues($body) { $values = []; @@ -39,6 +59,14 @@ protected function getValues($body) return $values[1]; } + /** + * Replace a single placeholder. + * + * @param string $body + * @param string $valueMatch + * @param string $replacer + * @return string + */ protected function replace($body, $valueMatch, $replacer) { $body = str_replace('{'.$replacer.'}', $valueMatch, $body); diff --git a/src/Notifynder/Senders/MultipleSender.php b/src/Notifynder/Senders/MultipleSender.php index 24ad3b4..62dbea7 100644 --- a/src/Notifynder/Senders/MultipleSender.php +++ b/src/Notifynder/Senders/MultipleSender.php @@ -5,18 +5,39 @@ use Fenos\Notifynder\Contracts\SenderContract; use Fenos\Notifynder\Contracts\SenderManagerContract; +/** + * Class MultipleSender + * @package Fenos\Notifynder\Senders + */ class MultipleSender implements SenderContract { + /** + * @var array + */ protected $notifications; + /** + * @var \Illuminate\Database\DatabaseManager + */ protected $database; + /** + * MultipleSender constructor. + * + * @param array $notifications + */ public function __construct(array $notifications) { $this->notifications = $notifications; $this->database = app('db'); } + /** + * Send all notifications. + * + * @param SenderManagerContract $sender + * @return bool + */ public function send(SenderManagerContract $sender) { $model = notifynder_config()->getNotificationModel(); @@ -35,6 +56,6 @@ public function send(SenderManagerContract $sender) ->insert($this->notifications); $this->database->commit(); - return $insert; + return (bool) $insert; } } diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 67f92a0..665a337 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -8,15 +8,33 @@ use Fenos\Notifynder\Contracts\SenderManagerContract; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; +/** + * Class OnceSender + * @package Fenos\Notifynder\Senders + */ class OnceSender implements SenderContract { + /** + * @var array + */ protected $notifications; + /** + * OnceSender constructor. + * + * @param array $notifications + */ public function __construct(array $notifications) { $this->notifications = $notifications; } + /** + * Send the notification once. + * + * @param SenderManagerContract $sender + * @return bool + */ public function send(SenderManagerContract $sender) { $success = true; @@ -32,6 +50,12 @@ public function send(SenderManagerContract $sender) return $success; } + /** + * Get the base query. + * + * @param Notification $notification + * @return \Illuminate\Database\Eloquent\Builder + */ protected function getQuery(Notification $notification) { $query = $this->getQueryInstance(); @@ -52,6 +76,9 @@ protected function getQuery(Notification $notification) return $query; } + /** + * @return \Illuminate\Database\Eloquent\Builder + */ protected function getQueryInstance() { $model = notifynder_config()->getNotificationModel(); diff --git a/src/Notifynder/Senders/SingleSender.php b/src/Notifynder/Senders/SingleSender.php index 97dc286..c71dba3 100644 --- a/src/Notifynder/Senders/SingleSender.php +++ b/src/Notifynder/Senders/SingleSender.php @@ -6,15 +6,33 @@ use Fenos\Notifynder\Contracts\SenderManagerContract; use Fenos\Notifynder\Models\Notification; +/** + * Class SingleSender + * @package Fenos\Notifynder\Senders + */ class SingleSender implements SenderContract { + /** + * @var \Fenos\Notifynder\Builder\Notification + */ protected $notification; + /** + * SingleSender constructor. + * + * @param array $notifications + */ public function __construct(array $notifications) { $this->notification = array_values($notifications)[0]; } + /** + * Send the single notification. + * + * @param SenderManagerContract $sender + * @return bool + */ public function send(SenderManagerContract $sender) { $notification = new Notification($this->notification); diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 11d7b4f..6d105a1 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -3,10 +3,18 @@ namespace Fenos\Notifynder\Traits; use Fenos\Notifynder\Helpers\TypeChecker; -use Fenos\Notifynder\Models\Notification; +/** + * Class Notifable + * @package Fenos\Notifynder\Traits + */ trait Notifable { + /** + * Get the notifications Relationship. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany + */ public function notifications() { $model = notifynder_config()->getNotificationModel(); @@ -17,25 +25,49 @@ public function notifications() return $this->hasMany($model, 'to_id'); } + /** + * Get a new NotifynderManager instance with the given category. + * + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return \Fenos\Notifynder\Managers\NotifynderManager + */ public function notifynder($category) { return app('notifynder')->category($category); } + /** + * Get a new NotifynderManager instance with the given category and $this as the sender. + * + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return \Fenos\Notifynder\Managers\NotifynderManager + */ public function sendNotificationFrom($category) { return $this->notifynder($category)->from($this); } + /** + * Get a new NotifynderManager instance with the given category and $this as the receiver. + * + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return \Fenos\Notifynder\Managers\NotifynderManager + */ public function sendNotificationTo($category) { return $this->notifynder($category)->to($this); } + /** + * Read a single Notification. + * + * @param int $notification + * @return bool + */ public function readNotification($notification) { if (! TypeChecker::isNotification($notification, false)) { - $notification = Notification::firstOrFail($notification); + $notification = $this->notifications()->firstOrFail($notification); } if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { @@ -45,15 +77,26 @@ public function readNotification($notification) return false; } + /** + * Read all Notifications. + * + * @return mixed + */ public function readAllNotifications() { return $this->notifications()->update(['read' => 1]); } + /** + * Unread a single Notification. + * + * @param int $notification + * @return bool + */ public function unreadNotification($notification) { if (! TypeChecker::isNotification($notification, false)) { - $notification = Notification::firstOrFail($notification); + $notification = $this->notifications()->firstOrFail($notification); } if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { @@ -63,11 +106,33 @@ public function unreadNotification($notification) return false; } + /** + * Unread all Notifications. + * + * @return mixed + */ + public function unreadAllNotifications() + { + return $this->notifications()->update(['read' => 0]); + } + + /** + * Count unread notifications. + * + * @return int + */ public function countUnreadNotifications() { return $this->notifications()->byRead(0)->count(); } + /** + * Get all Notifications ordered by creation and optional limit. + * + * @param null|int $limit + * @param string $order + * @return \Illuminate\Database\Eloquent\Collection + */ public function getNotifications($limit = null, $order = 'desc') { $query = $this->notifications()->orderBy('created_at', $order); From b0ae458db4574e190ed4a905b6fe4ff654ba2f98 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 10:02:45 +0000 Subject: [PATCH 167/210] Applied fixes from StyleCI --- src/Notifynder/Builder/Builder.php | 3 +-- src/Notifynder/Builder/Notification.php | 3 +-- src/Notifynder/Collections/Config.php | 7 ++----- src/Notifynder/Contracts/ConfigContract.php | 3 +-- src/Notifynder/Contracts/SenderContract.php | 3 +-- src/Notifynder/Contracts/SenderManagerContract.php | 3 +-- src/Notifynder/Helpers/TypeChecker.php | 3 +-- src/Notifynder/Managers/NotifynderManager.php | 7 ++----- src/Notifynder/Managers/SenderManager.php | 3 +-- src/Notifynder/Models/Notification.php | 3 +-- src/Notifynder/Models/NotificationCategory.php | 3 +-- src/Notifynder/Models/NotificationGroup.php | 3 +-- src/Notifynder/NotifynderServiceProvider.php | 3 +-- src/Notifynder/Parsers/NotificationParser.php | 5 ++--- src/Notifynder/Senders/MultipleSender.php | 3 +-- src/Notifynder/Senders/OnceSender.php | 5 ++--- src/Notifynder/Senders/SingleSender.php | 3 +-- src/Notifynder/Traits/Notifable.php | 5 ++--- 18 files changed, 23 insertions(+), 45 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 06d6a9f..836650f 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -11,8 +11,7 @@ use Illuminate\Database\Eloquent\Model; /** - * Class Builder - * @package Fenos\Notifynder\Builder + * Class Builder. */ class Builder implements ArrayAccess { diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index 12e60ed..f1b8124 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -9,8 +9,7 @@ use JsonSerializable; /** - * Class Notification - * @package Fenos\Notifynder\Builder + * Class Notification. */ class Notification implements Arrayable, ArrayAccess, Jsonable, JsonSerializable { diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index c31ad8b..31bf30e 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -8,8 +8,7 @@ use InvalidArgumentException; /** - * Class Config - * @package Fenos\Notifynder\Collections + * Class Config. */ class Config implements ConfigContract { @@ -129,9 +128,7 @@ public function set($key, $value = null) app('config')->set('notifynder.'.$key, $value); } - /** - * - */ + public function reload() { $this->items = app('config')->get('notifynder'); diff --git a/src/Notifynder/Contracts/ConfigContract.php b/src/Notifynder/Contracts/ConfigContract.php index 64de064..c03344b 100644 --- a/src/Notifynder/Contracts/ConfigContract.php +++ b/src/Notifynder/Contracts/ConfigContract.php @@ -3,8 +3,7 @@ namespace Fenos\Notifynder\Contracts; /** - * Interface ConfigContract - * @package Fenos\Notifynder\Contracts + * Interface ConfigContract. */ interface ConfigContract { diff --git a/src/Notifynder/Contracts/SenderContract.php b/src/Notifynder/Contracts/SenderContract.php index 1021fe4..4d8c02a 100644 --- a/src/Notifynder/Contracts/SenderContract.php +++ b/src/Notifynder/Contracts/SenderContract.php @@ -3,8 +3,7 @@ namespace Fenos\Notifynder\Contracts; /** - * Interface SenderContract - * @package Fenos\Notifynder\Contracts + * Interface SenderContract. */ interface SenderContract { diff --git a/src/Notifynder/Contracts/SenderManagerContract.php b/src/Notifynder/Contracts/SenderManagerContract.php index 945325f..028b90f 100644 --- a/src/Notifynder/Contracts/SenderManagerContract.php +++ b/src/Notifynder/Contracts/SenderManagerContract.php @@ -5,8 +5,7 @@ use Closure; /** - * Interface SenderManagerContract - * @package Fenos\Notifynder\Contracts + * Interface SenderManagerContract. */ interface SenderManagerContract { diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index 14c4722..fea147a 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -8,8 +8,7 @@ use Traversable; /** - * Class TypeChecker - * @package Fenos\Notifynder\Helpers + * Class TypeChecker. */ class TypeChecker { diff --git a/src/Notifynder/Managers/NotifynderManager.php b/src/Notifynder/Managers/NotifynderManager.php index 3f4d823..c548745 100755 --- a/src/Notifynder/Managers/NotifynderManager.php +++ b/src/Notifynder/Managers/NotifynderManager.php @@ -10,8 +10,7 @@ use Illuminate\Support\Str; /** - * Class NotifynderManager - * @package Fenos\Notifynder\Managers + * Class NotifynderManager. */ class NotifynderManager implements NotifynderManagerContract { @@ -91,9 +90,7 @@ public function sender() return $this->sender; } - /** - * - */ + protected function reset() { $this->builder = null; diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index 1fb63eb..33d25ad 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -11,8 +11,7 @@ use Illuminate\Support\Str; /** - * Class SenderManager - * @package Fenos\Notifynder\Managers + * Class SenderManager. */ class SenderManager implements SenderManagerContract { diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index a830817..d261736 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -8,8 +8,7 @@ use Illuminate\Database\Eloquent\Model; /** - * Class Notification - * @package Fenos\Notifynder\Models + * Class Notification. */ class Notification extends Model { diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 2bbdeb7..7f3aafb 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -6,8 +6,7 @@ use Illuminate\Database\Eloquent\Model; /** - * Class NotificationCategory - * @package Fenos\Notifynder\Models + * Class NotificationCategory. */ class NotificationCategory extends Model { diff --git a/src/Notifynder/Models/NotificationGroup.php b/src/Notifynder/Models/NotificationGroup.php index 6fd514e..6c98abe 100755 --- a/src/Notifynder/Models/NotificationGroup.php +++ b/src/Notifynder/Models/NotificationGroup.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** - * Class NotificationGroup - * @package Fenos\Notifynder\Models + * Class NotificationGroup. */ class NotificationGroup extends Model { diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index e21a2dc..1b926f3 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -14,8 +14,7 @@ use Illuminate\Support\ServiceProvider; /** - * Class NotifynderServiceProvider - * @package Fenos\Notifynder + * Class NotifynderServiceProvider. */ class NotifynderServiceProvider extends ServiceProvider { diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index 43822fd..ad730df 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -6,13 +6,12 @@ use Fenos\Notifynder\Models\Notification; /** - * Class NotificationParser - * @package Fenos\Notifynder\Parsers + * Class NotificationParser. */ class NotificationParser { /** - * Regex-search-rule + * Regex-search-rule. */ const RULE = '/\{([a-zA-Z0-9_\.]+)\}/m'; diff --git a/src/Notifynder/Senders/MultipleSender.php b/src/Notifynder/Senders/MultipleSender.php index 62dbea7..3046878 100644 --- a/src/Notifynder/Senders/MultipleSender.php +++ b/src/Notifynder/Senders/MultipleSender.php @@ -6,8 +6,7 @@ use Fenos\Notifynder\Contracts\SenderManagerContract; /** - * Class MultipleSender - * @package Fenos\Notifynder\Senders + * Class MultipleSender. */ class MultipleSender implements SenderContract { diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 665a337..19f8ba8 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -9,8 +9,7 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; /** - * Class OnceSender - * @package Fenos\Notifynder\Senders + * Class OnceSender. */ class OnceSender implements SenderContract { @@ -21,7 +20,7 @@ class OnceSender implements SenderContract /** * OnceSender constructor. - * + * * @param array $notifications */ public function __construct(array $notifications) diff --git a/src/Notifynder/Senders/SingleSender.php b/src/Notifynder/Senders/SingleSender.php index c71dba3..d4ef585 100644 --- a/src/Notifynder/Senders/SingleSender.php +++ b/src/Notifynder/Senders/SingleSender.php @@ -7,8 +7,7 @@ use Fenos\Notifynder\Models\Notification; /** - * Class SingleSender - * @package Fenos\Notifynder\Senders + * Class SingleSender. */ class SingleSender implements SenderContract { diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 6d105a1..fd58994 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -5,8 +5,7 @@ use Fenos\Notifynder\Helpers\TypeChecker; /** - * Class Notifable - * @package Fenos\Notifynder\Traits + * Class Notifable. */ trait Notifable { @@ -128,7 +127,7 @@ public function countUnreadNotifications() /** * Get all Notifications ordered by creation and optional limit. - * + * * @param null|int $limit * @param string $order * @return \Illuminate\Database\Eloquent\Collection From 6a0b0ee034a82e2d13e590c532c8f5d36a1941cb Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 13:17:35 +0200 Subject: [PATCH 168/210] add codeclimate code coverage report --- .travis.yml | 6 ++++++ composer.json | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 40b0a9f..6fd6538 100755 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,11 @@ cache: directories: - $HOME/.composer/cache +## Addons used by this package +addons: + code_climate: + repo_token: ${CC_TOKEN} + ## List all PHP versions to test with php: - 5.5 @@ -36,6 +41,7 @@ before_script: script: ## - vendor/bin/phpspec run - vendor/bin/phpunit + - vendor/bin/test-reporter ## - php CoverageChecker.php ./build/logs/clover.xml 65 ## Send Build Notifications to Slack diff --git a/composer.json b/composer.json index b75d4e4..8b19953 100755 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "phpspec/phpspec": "~2.1", "laracasts/testdummy": "~2.0", "orchestra/testbench": "~3.0", - "doctrine/dbal": "^2.5" + "doctrine/dbal": "^2.5", + "codeclimate/php-test-reporter": "^0.3.2" }, "autoload": { "classmap": [ From ead7c0d070d81cad1f3de25783e68d272e0c7739 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 13:26:26 +0200 Subject: [PATCH 169/210] [skip ci] update readme docu --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 16569bb..430d6e5 100755 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You get started in a couple of minutes to "enable" notifications in your Laravel Compatible DBs: **MySql** - **PostgresSql** - **Sqlite** -Documentation: **[Notifynder Wiki](https://github.com/fenos/Notifynder/wiki)** +Documentation: **[Notifynder Docu](http://notifynder.info)** - - - From 2e3385aec0244a3a78e48e3921c027a2cf310234 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 13:27:53 +0200 Subject: [PATCH 170/210] [skip ci] update readme --- README.md | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 430d6e5..ea18c49 100755 --- a/README.md +++ b/README.md @@ -19,14 +19,14 @@ Notifynder 4 - Laravel 5 Notifynder is designed to manage notifications in a powerful and easy way. With the flexibility that Notifynder offer, It provide a complete API to work with your notifications, -such as storing, retriving, and organise your codebase to handle hundreds of notifications. +such as storing, retrieving, and organise your codebase to handle hundreds of notifications. You get started in a couple of minutes to "enable" notifications in your Laravel Project. Compatible DBs: **MySql** - **PostgresSql** - **Sqlite** Documentation: **[Notifynder Docu](http://notifynder.info)** -- - - +----- ## Installation ## @@ -34,15 +34,21 @@ Documentation: **[Notifynder Docu](http://notifynder.info)** Add it on your `composer.json` - "fenos/notifynder": "^4.0" +``` +"fenos/notifynder": "^4.0" +``` and run - composer update +``` +composer update +``` or run - composer require fenos/notifynder +``` +composer require fenos/notifynder +``` ### Step 2 ### @@ -51,11 +57,15 @@ Add the following string to `config/app.php` **Providers array:** - Fenos\Notifynder\NotifynderServiceProvider::class, +``` +Fenos\Notifynder\NotifynderServiceProvider::class, +``` **Aliases array:** - 'Notifynder' => Fenos\Notifynder\Facades\Notifynder::class, +``` +'Notifynder' => Fenos\Notifynder\Facades\Notifynder::class, +``` ### Step 3 ### @@ -64,11 +74,15 @@ Add the following string to `config/app.php` Publish the migration as well as the configuration of notifynder with the following command: - php artisan vendor:publish --provider="Fenos\Notifynder\NotifynderServiceProvider" +``` +php artisan vendor:publish --provider="Fenos\Notifynder\NotifynderServiceProvider" +``` Run the migration - php artisan migrate +``` +php artisan migrate +``` ## Usage ## From 91d1231252852f9edfbc8f02330d3475fc049a99 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 13:28:35 +0200 Subject: [PATCH 171/210] [skip ci] update readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index ea18c49..53b0dcf 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -Notifynder 4 - Laravel 5 -======================== +# Notifynder 4 - Laravel 5 [![GitHub release](https://img.shields.io/github/release/fenos/Notifynder.svg?style=flat-square)](https://github.com/fenos/Notifynder/releases) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/fenos/Notifynder/master/LICENSE) From 7efc98053eec76bf6acf62e0f67802d2dce08d98 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 13:40:22 +0200 Subject: [PATCH 172/210] remove duplicate code in migration publisher --- src/Notifynder/NotifynderServiceProvider.php | 46 ++++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 1b926f3..a196aba 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -18,6 +18,19 @@ */ class NotifynderServiceProvider extends ServiceProvider { + protected $migrations = [ + 'NotificationCategories' => '2014_02_10_145728_notification_categories', + 'CreateNotificationGroupsTable' => '2014_08_01_210813_create_notification_groups_table', + 'CreateNotificationCategoryNotificationGroupTable' => '2014_08_01_211045_create_notification_category_notification_group_table', + 'CreateNotificationsTable' => '2015_05_05_212549_create_notifications_table', + 'AddExpireTimeColumnToNotificationTable' => '2015_06_06_211555_add_expire_time_column_to_notification_table', + 'ChangeTypeToExtraInNotificationsTable' => '2015_06_06_211555_change_type_to_extra_in_notifications_table', + 'AlterCategoryNameToUnique' => '2015_06_07_211555_alter_category_name_to_unique', + 'MakeNotificationUrlNullable' => '2016_04_19_200827_make_notification_url_nullable', + 'AddStackIdToNotifications' => '2016_05_19_144531_add_stack_id_to_notifications', + 'UpdateVersion4NotificationsTable' => '2016_07_01_153156_update_version4_notifications_table', + ]; + /** * Register the service provider. * @@ -135,35 +148,10 @@ protected function config() */ protected function migration() { - if (! class_exists('NotificationCategories')) { - $this->publishMigration('2014_02_10_145728_notification_categories'); - } - if (! class_exists('CreateNotificationGroupsTable')) { - $this->publishMigration('2014_08_01_210813_create_notification_groups_table'); - } - if (! class_exists('CreateNotificationCategoryNotificationGroupTable')) { - $this->publishMigration('2014_08_01_211045_create_notification_category_notification_group_table'); - } - if (! class_exists('CreateNotificationsTable')) { - $this->publishMigration('2015_05_05_212549_create_notifications_table'); - } - if (! class_exists('AddExpireTimeColumnToNotificationTable')) { - $this->publishMigration('2015_06_06_211555_add_expire_time_column_to_notification_table'); - } - if (! class_exists('ChangeTypeToExtraInNotificationsTable')) { - $this->publishMigration('2015_06_06_211555_change_type_to_extra_in_notifications_table'); - } - if (! class_exists('AlterCategoryNameToUnique')) { - $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique'); - } - if (! class_exists('MakeNotificationUrlNullable')) { - $this->publishMigration('2016_04_19_200827_make_notification_url_nullable'); - } - if (! class_exists('AddStackIdToNotifications')) { - $this->publishMigration('2016_05_19_144531_add_stack_id_to_notifications'); - } - if (! class_exists('UpdateVersion4NotificationsTable')) { - $this->publishMigration('2016_07_01_153156_update_version4_notifications_table'); + foreach($this->migrations as $class => $file) { + if (! class_exists($class)) { + $this->publishMigration($file); + } } } From 1b96486024ee3a0eef5b0e19c3679bf390b12958 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 11:40:30 +0000 Subject: [PATCH 173/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/NotifynderServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index a196aba..239f19a 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -148,7 +148,7 @@ protected function config() */ protected function migration() { - foreach($this->migrations as $class => $file) { + foreach ($this->migrations as $class => $file) { if (! class_exists($class)) { $this->publishMigration($file); } From 52614309e3a8d1ede01d6b33252876027488ca47 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 13:48:59 +0200 Subject: [PATCH 174/210] configure scrutinizer remove hhvm from travis --- .scrutinizer.yml | 9 +++++++++ .travis.yml | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..a76e4e7 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,9 @@ +checks: + php: true +filter: + paths: ["src/Notifynder/*"] + excluded_paths: + - tests/* +build: + environment: + php: 7.0.6 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 6fd6538..405e4c3 100755 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,6 @@ php: - 5.5 - 5.6 - 7.0 - - hhvm ## Define all ENV vars to test with env: From cf59bd9be6fea73d491dfc65fbe40d9bb48ab3df Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 14:04:51 +0200 Subject: [PATCH 175/210] remove duplicated code --- src/Notifynder/Builder/Builder.php | 8 +--- src/Notifynder/Helpers/TypeChecker.php | 2 +- src/Notifynder/Models/Notification.php | 8 +--- .../Models/NotificationCategory.php | 16 ++++++++ src/Notifynder/Traits/Notifable.php | 40 +++++++++++-------- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 836650f..e990df0 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -39,13 +39,7 @@ public function __construct() */ public function category($category) { - $categoryId = $category; - if ($category instanceof NotificationCategory) { - $categoryId = $category->getKey(); - } elseif (! is_numeric($category)) { - $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); - } - + $categoryId = NotificationCategory::getIdByCategory($category); $this->setNotificationData('category_id', $categoryId); return $this; diff --git a/src/Notifynder/Helpers/TypeChecker.php b/src/Notifynder/Helpers/TypeChecker.php index fea147a..ca2d318 100644 --- a/src/Notifynder/Helpers/TypeChecker.php +++ b/src/Notifynder/Helpers/TypeChecker.php @@ -77,7 +77,7 @@ public static function isDate($value, $strict = true) */ public static function isArray($value, $strict = true) { - if (is_array($value) && count($value) > 0) { + if (self::isIterable($value, $strict) && is_array($value)) { return true; } diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index d261736..9d0ce42 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -181,13 +181,7 @@ public function isAnonymous() */ public function scopeByCategory(Builder $query, $category) { - $categoryId = $category; - if ($category instanceof NotificationCategory) { - $categoryId = $category->getKey(); - } elseif (! is_numeric($category)) { - $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); - } - + $categoryId = NotificationCategory::getIdByCategory($category); return $query->where('category_id', $categoryId); } diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 7f3aafb..455942e 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -58,4 +58,20 @@ public function scopeByName(Builder $query, $name) { return $query->where('name', $name); } + + /** + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return int + */ + public static function getIdByCategory($category) + { + $categoryId = $category; + if ($category instanceof NotificationCategory) { + $categoryId = $category->getKey(); + } elseif (! is_numeric($category)) { + $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); + } + + return $categoryId; + } } diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index fd58994..e5c9171 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -65,46 +65,52 @@ public function sendNotificationTo($category) */ public function readNotification($notification) { - if (! TypeChecker::isNotification($notification, false)) { - $notification = $this->notifications()->firstOrFail($notification); - } - - if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { - return $notification->read(); - } - - return false; + return $this->updateSingleReadStatus($notification, 1); } /** - * Read all Notifications. + * Unread a single Notification. * - * @return mixed + * @param int $notification + * @return bool */ - public function readAllNotifications() + public function unreadNotification($notification) { - return $this->notifications()->update(['read' => 1]); + return $this->updateSingleReadStatus($notification, 0); } /** - * Unread a single Notification. - * * @param int $notification + * @param int $value * @return bool */ - public function unreadNotification($notification) + protected function updateSingleReadStatus($notification, $value) { if (! TypeChecker::isNotification($notification, false)) { $notification = $this->notifications()->firstOrFail($notification); } if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { - return $notification->unread(); + if($value) { + return $notification->read(); + } else { + return $notification->unread(); + } } return false; } + /** + * Read all Notifications. + * + * @return mixed + */ + public function readAllNotifications() + { + return $this->notifications()->update(['read' => 1]); + } + /** * Unread all Notifications. * From 6b9b42b5b67da820c000421a61df9c02fb2fac66 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 12:04:58 +0000 Subject: [PATCH 176/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Models/Notification.php | 1 + src/Notifynder/Models/NotificationCategory.php | 4 ++-- src/Notifynder/Traits/Notifable.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index 9d0ce42..a2cfc71 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -182,6 +182,7 @@ public function isAnonymous() public function scopeByCategory(Builder $query, $category) { $categoryId = NotificationCategory::getIdByCategory($category); + return $query->where('category_id', $categoryId); } diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 455942e..a7dcb39 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -66,10 +66,10 @@ public function scopeByName(Builder $query, $name) public static function getIdByCategory($category) { $categoryId = $category; - if ($category instanceof NotificationCategory) { + if ($category instanceof self) { $categoryId = $category->getKey(); } elseif (! is_numeric($category)) { - $categoryId = NotificationCategory::byName($category)->firstOrFail()->getKey(); + $categoryId = self::byName($category)->firstOrFail()->getKey(); } return $categoryId; diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index e5c9171..b94755c 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -91,7 +91,7 @@ protected function updateSingleReadStatus($notification, $value) } if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { - if($value) { + if ($value) { return $notification->read(); } else { return $notification->unread(); From 95d27fc08a4d2ba6ddf10b730e64b219b6a2a928 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 25 Aug 2016 14:05:53 +0200 Subject: [PATCH 177/210] reenable the coverage checker --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 405e4c3..74946d1 100755 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ script: ## - vendor/bin/phpspec run - vendor/bin/phpunit - vendor/bin/test-reporter -## - php CoverageChecker.php ./build/logs/clover.xml 65 + - php CoverageChecker.php build/logs/clover.xml 65 ## Send Build Notifications to Slack notifications: From 05140560ef4e9426545d249f68952a0b8829b9d2 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 11:17:38 +0200 Subject: [PATCH 178/210] Issue #196 enable multiple calls of `extra()` --- src/Notifynder/Builder/Builder.php | 47 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index e990df0..3d873ea 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -34,6 +34,8 @@ public function __construct() } /** + * Set the category for this notification. + * * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category * @return $this */ @@ -46,6 +48,8 @@ public function category($category) } /** + * Set the sender for this notification. + * * @return $this */ public function from() @@ -57,6 +61,8 @@ public function from() } /** + * Set the sender anonymous for this notification. + * * @return $this */ public function anonymous() @@ -68,6 +74,8 @@ public function anonymous() } /** + * Set the receiver for this notification. + * * @return $this */ public function to() @@ -79,6 +87,8 @@ public function to() } /** + * Set the url for this notification. + * * @param string $url * @return $this */ @@ -91,10 +101,12 @@ public function url($url) } /** + * Set the expire date for this notification. + * * @param Carbon|\DateTime $datetime * @return $this */ - public function expire($datetime) + public function expire(Carbon $datetime) { TypeChecker::isDate($datetime); $carbon = new Carbon($datetime); @@ -104,12 +116,19 @@ public function expire($datetime) } /** + * Set the extra values for this notification. + * You can extend the existing extras or override them - important for multiple calls of extra() on one notification. + * * @param array $extra + * @param bool $override * @return $this */ - public function extra(array $extra = []) + public function extra(array $extra = [], $override = true) { TypeChecker::isArray($extra); + if(!$override) { + $extra = array_merge($this->getNotificationData('extra', []), $extra); + } $this->setNotificationData('extra', $extra); return $this; @@ -144,6 +163,8 @@ public function setField($key, $value) } /** + * Set polymorphic model values. + * * @param array $entity * @param string $property */ @@ -170,6 +191,20 @@ protected function setEntityData($entity, $property) } /** + * Get a single value of this notification. + * + * @param string $key + * @param null|mixed $default + * @return mixed + */ + protected function getNotificationData($key, $default = null) + { + return $this->notification->get($key, $default); + } + + /** + * Set a single value of this notification. + * * @param string $key * @param mixed $value */ @@ -179,6 +214,8 @@ protected function setNotificationData($key, $value) } /** + * Get the current notification. + * * @return Notification * @throws UnvalidNotificationException */ @@ -194,6 +231,8 @@ public function getNotification() } /** + * Add a notification to the notifications array. + * * @param Notification $notification */ public function addNotification(Notification $notification) @@ -202,6 +241,8 @@ public function addNotification(Notification $notification) } /** + * Get all notifications. + * * @return array * @throws UnvalidNotificationException */ @@ -215,6 +256,8 @@ public function getNotifications() } /** + * Loop over data and call the callback with a new Builder instance and the key and value of the iterated data. + * * @param array|\Traversable $data * @param Closure $callback * @return $this From 3a5910189bcf930f1cea475036342158eb08ec16 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 09:18:13 +0000 Subject: [PATCH 179/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Builder/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Builder/Builder.php b/src/Notifynder/Builder/Builder.php index 3d873ea..5a6ee15 100755 --- a/src/Notifynder/Builder/Builder.php +++ b/src/Notifynder/Builder/Builder.php @@ -126,7 +126,7 @@ public function expire(Carbon $datetime) public function extra(array $extra = [], $override = true) { TypeChecker::isArray($extra); - if(!$override) { + if (! $override) { $extra = array_merge($this->getNotificationData('extra', []), $extra); } $this->setNotificationData('extra', $extra); From 5f4f8816947eda3ff891f50a2cfa72f9f262b566 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 11:25:14 +0200 Subject: [PATCH 180/210] Issue #196 add unittests for this --- tests/integration/Builder/BuilderTest.php | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php index 57904bb..6c2e8b6 100644 --- a/tests/integration/Builder/BuilderTest.php +++ b/tests/integration/Builder/BuilderTest.php @@ -70,6 +70,51 @@ public function testCreateSingleNotificationWithAll() $this->assertInstanceOf(Carbon::class, $notification->expires_at); } + public function testCreateSingleNotificationWithExtendedExtra() + { + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(1) + ->to(2) + ->extra([ + 'foo' => 'bar', + ], false) + ->extra([ + 'hello' => 'world', + ], false) + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + + $this->assertInternalType('array', $notification->extra); + $this->assertCount(2, $notification->extra); + $this->assertSame('bar', $notification->extra['foo']); + $this->assertSame('world', $notification->extra['hello']); + } + + public function testCreateSingleNotificationWithOverriddenExtra() + { + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(1) + ->to(2) + ->extra([ + 'foo' => 'bar', + ], true) + ->extra([ + 'hello' => 'world', + ], true) + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + + $this->assertInternalType('array', $notification->extra); + $this->assertCount(1, $notification->extra); + $this->assertSame('world', $notification->extra['hello']); + } + public function testCreateSingleNotificationAndGetArray() { $builder = new Builder(); From 1e1a7ad1152d10da8b87bf426c2b128cb97dfe32 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 11:47:58 +0200 Subject: [PATCH 181/210] update readme with a versioning part --- README.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 53b0dcf..8676254 100755 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Documentation: **[Notifynder Docu](http://notifynder.info)** ----- -## Installation ## +## Installation -### Step 1 ### +### Step 1 Add it on your `composer.json` @@ -50,7 +50,7 @@ composer require fenos/notifynder ``` -### Step 2 ### +### Step 2 Add the following string to `config/app.php` @@ -67,9 +67,9 @@ Fenos\Notifynder\NotifynderServiceProvider::class, ``` -### Step 3 ### +### Step 3 -#### Migration #### +#### Migration Publish the migration as well as the configuration of notifynder with the following command: @@ -83,12 +83,26 @@ Run the migration php artisan migrate ``` -## Usage ## +## Usage This Branch isn't ready for any kind of usage! It's development in progress and will bring a whole new code-base for this package. Everyone is welcome to support us or give feedback for the new major version in our Slack Team. -## Contributors ## +## Versioning + +Starting with `v4.0.0` we are following the [Semantic Versioning Standard](http://semver.org). + +### Summary + +Given a version number `MAJOR`.`MINOR`.`PATCH`, increment the: + +* **MAJOR** version when you make incompatible API changes, +* **MINOR** version when you add functionality in a backwards-compatible manner, and +* **PATCH** version when you make backwards-compatible bug fixes. + +Additional labels for pre-release (`alpha`, `beta`, `rc`) are available as extensions to the `MAJOR`.`MINOR`.`PATCH` format. + +## Contributors Thanks for everyone [who contributed](https://github.com/fenos/Notifynder/graphs/contributors) to Notifynder and a special thanks for the most active contributors From 41fc8f6c6ae8ba2870cb6e99f0d3042bc1303adb Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 12:22:14 +0200 Subject: [PATCH 182/210] add more unittests increase code coverage to 70% --- .travis.yml | 2 +- src/Notifynder/Traits/Notifable.php | 2 +- tests/NotifynderTestCase.php | 48 ++++++++++++++-- .../Facades/NotifynderFacadeTest.php | 21 +++++++ tests/integration/Traits/NotifableTest.php | 57 +++++++++++++++++++ .../2016_08_26_100534_create_cars_table.php | 32 +++++++++++ tests/models/Car.php | 17 ++++++ 7 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 tests/integration/Facades/NotifynderFacadeTest.php create mode 100644 tests/migrations/2016_08_26_100534_create_cars_table.php create mode 100644 tests/models/Car.php diff --git a/.travis.yml b/.travis.yml index 74946d1..33f457a 100755 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ script: ## - vendor/bin/phpspec run - vendor/bin/phpunit - vendor/bin/test-reporter - - php CoverageChecker.php build/logs/clover.xml 65 + - php CoverageChecker.php build/logs/clover.xml 70 ## Send Build Notifications to Slack notifications: diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index b94755c..d673599 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -87,7 +87,7 @@ public function unreadNotification($notification) protected function updateSingleReadStatus($notification, $value) { if (! TypeChecker::isNotification($notification, false)) { - $notification = $this->notifications()->firstOrFail($notification); + $notification = $this->notifications()->findOrFail($notification); } if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index 84b7b1f..6d0cf99 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -2,12 +2,25 @@ use Orchestra\Testbench\TestCase as OrchestraTestCase; use Fenos\Tests\Models\User; +use Fenos\Tests\Models\Car; +use Fenos\Notifynder\NotifynderServiceProvider; +use Fenos\Notifynder\Facades\Notifynder as NotifynderFacade; +use Illuminate\Database\Eloquent\Model; abstract class NotifynderTestCase extends OrchestraTestCase { protected function getPackageProviders($app) { - return ['Fenos\Notifynder\NotifynderServiceProvider']; + return [ + NotifynderServiceProvider::class, + ]; + } + + protected function getPackageAliases($app) + { + return [ + 'Notifynder' => NotifynderFacade::class, + ]; } public function setUp() @@ -27,9 +40,9 @@ protected function getEnvironmentSetUp($app) { $app['config']->set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', [ - 'driver' => 'sqlite', + 'driver' => 'sqlite', 'database' => ':memory:', - 'prefix' => '', + 'prefix' => '', ]); } @@ -47,18 +60,43 @@ protected function migrate($artisan, $path = '/../../../../src/migrations') { $artisan->call('migrate', [ '--database' => 'testbench', - '--path' => $path, + '--path' => $path, ]); } protected function createUser(array $attributes = []) { $attributes = array_merge([ - 'id' => 1, 'firstname' => 'John', 'lastname' => 'Doe', ], $attributes); return User::create($attributes); } + + protected function createCar(array $attributes = []) + { + $attributes = array_merge([ + 'brand' => 'Audi', + 'model' => 'A6', + ], $attributes); + + return Car::create($attributes); + } + + protected function sendNotificationTo(Model $model) + { + return $model + ->sendNotificationTo(1) + ->from(2) + ->send(); + } + + protected function sendNotificationsTo(Model $model, $amount = 10) + { + while($amount > 0) { + $this->sendNotificationTo($model); + $amount--; + } + } } diff --git a/tests/integration/Facades/NotifynderFacadeTest.php b/tests/integration/Facades/NotifynderFacadeTest.php new file mode 100644 index 0000000..dc53262 --- /dev/null +++ b/tests/integration/Facades/NotifynderFacadeTest.php @@ -0,0 +1,21 @@ +from(1) + ->to(2) + ->send(); + + $this->assertTrue($sent); + + $notifications = ModelNotification::all(); + $this->assertCount(1, $notifications); + $this->assertInstanceOf(EloquentCollection::class, $notifications); + } +} diff --git a/tests/integration/Traits/NotifableTest.php b/tests/integration/Traits/NotifableTest.php index c3da897..db490b8 100644 --- a/tests/integration/Traits/NotifableTest.php +++ b/tests/integration/Traits/NotifableTest.php @@ -48,4 +48,61 @@ public function testSendNotificationTo() $notifynder->send(); $this->assertCount(1, $user->notifications); } + + public function testNotificationsHasMany() + { + $user = $this->createUser(); + $user + ->sendNotificationTo(1) + ->from(2) + ->send(); + $this->assertCount(1, $user->notifications); + } + + public function testNotificationsMorphMany() + { + notifynder_config()->set('polymorphic', true); + + $user = $this->createUser(); + $this->sendNotificationTo($user); + $car = $this->createCar(); + $this->sendNotificationTo($car); + $this->assertCount(1, $user->notifications); + $this->assertCount(1, $car->notifications); + } + + public function testGetNotificationsDefault() + { + $user = $this->createUser(); + $this->sendNotificationsTo($user, 25); + $this->assertCount(25, $user->getNotifications()); + } + + public function testGetNotificationsLimited() + { + $user = $this->createUser(); + $this->sendNotificationsTo($user, 25); + $this->assertCount(10, $user->getNotifications(10)); + } + + public function testReadStatusRelatedMethods() + { + $user = $this->createUser(); + $this->sendNotificationsTo($user, 25); + $this->assertSame(25, $user->countUnreadNotifications()); + $this->assertSame(25, $user->readAllNotifications()); + $this->assertSame(0, $user->countUnreadNotifications()); + $this->assertSame(25, $user->unreadAllNotifications()); + $this->assertSame(25, $user->countUnreadNotifications()); + $notification = $user->notifications->first(); + $this->assertTrue($user->readNotification($notification)); + $this->assertSame(24, $user->countUnreadNotifications()); + $this->assertTrue($user->unreadNotification($notification->getKey())); + $this->assertSame(25, $user->countUnreadNotifications()); + + + $user2 = $this->createUser(); + $this->sendNotificationsTo($user2, 5); + $this->assertFalse($user->readNotification($user2->notifications()->first())); + } } diff --git a/tests/migrations/2016_08_26_100534_create_cars_table.php b/tests/migrations/2016_08_26_100534_create_cars_table.php new file mode 100644 index 0000000..8a534cc --- /dev/null +++ b/tests/migrations/2016_08_26_100534_create_cars_table.php @@ -0,0 +1,32 @@ +increments('id'); + $table->string('brand'); + $table->string('model'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('cars'); + } +} diff --git a/tests/models/Car.php b/tests/models/Car.php new file mode 100644 index 0000000..743af5e --- /dev/null +++ b/tests/models/Car.php @@ -0,0 +1,17 @@ + Date: Fri, 26 Aug 2016 10:22:21 +0000 Subject: [PATCH 183/210] Applied fixes from StyleCI [ci skip] [skip ci] --- tests/NotifynderTestCase.php | 2 +- tests/integration/Traits/NotifableTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index 6d0cf99..5c5a401 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -94,7 +94,7 @@ protected function sendNotificationTo(Model $model) protected function sendNotificationsTo(Model $model, $amount = 10) { - while($amount > 0) { + while ($amount > 0) { $this->sendNotificationTo($model); $amount--; } diff --git a/tests/integration/Traits/NotifableTest.php b/tests/integration/Traits/NotifableTest.php index db490b8..470c3e3 100644 --- a/tests/integration/Traits/NotifableTest.php +++ b/tests/integration/Traits/NotifableTest.php @@ -70,7 +70,7 @@ public function testNotificationsMorphMany() $this->assertCount(1, $user->notifications); $this->assertCount(1, $car->notifications); } - + public function testGetNotificationsDefault() { $user = $this->createUser(); From a51793350f4cadb882cde27e89346b35d3a72da8 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 12:34:50 +0200 Subject: [PATCH 184/210] add support for coveralls --- .coveralls.yml | 3 +++ .travis.yml | 1 + composer.json | 3 ++- phpunit.xml | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..b81810c --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,3 @@ +coverage_clover: build/logs/clover.xml +json_path: build/logs/coveralls-upload.json +service_name: travis-ci \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 33f457a..7355293 100755 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ script: - vendor/bin/phpunit - vendor/bin/test-reporter - php CoverageChecker.php build/logs/clover.xml 70 + - vendor/bin/coveralls -v ## Send Build Notifications to Slack notifications: diff --git a/composer.json b/composer.json index 8b19953..2561193 100755 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "laracasts/testdummy": "~2.0", "orchestra/testbench": "~3.0", "doctrine/dbal": "^2.5", - "codeclimate/php-test-reporter": "^0.3.2" + "codeclimate/php-test-reporter": "^0.3.2", + "satooshi/php-coveralls": "^1.0" }, "autoload": { "classmap": [ diff --git a/phpunit.xml b/phpunit.xml index 27329c7..ebefb65 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,6 +18,12 @@ ./src/Notifynder + + ./vendor + ./tests + ./spec + ./build + From 76890109660c68244cab6b251121989377903534 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 12:43:50 +0200 Subject: [PATCH 185/210] add support for coveralls --- .coveralls.yml | 3 +-- .travis.yml | 5 +++-- README.md | 10 +++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.coveralls.yml b/.coveralls.yml index b81810c..6d00a3d 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,3 +1,2 @@ coverage_clover: build/logs/clover.xml -json_path: build/logs/coveralls-upload.json -service_name: travis-ci \ No newline at end of file +json_path: build/logs/coveralls-upload.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7355293..4a7bf1d 100755 --- a/.travis.yml +++ b/.travis.yml @@ -38,10 +38,11 @@ before_script: ## Run test Scripts script: -## - vendor/bin/phpspec run - vendor/bin/phpunit - - vendor/bin/test-reporter - php CoverageChecker.php build/logs/clover.xml 70 + +after_script: + - vendor/bin/test-reporter - vendor/bin/coveralls -v ## Send Build Notifications to Slack diff --git a/README.md b/README.md index 8676254..899d84c 100755 --- a/README.md +++ b/README.md @@ -106,4 +106,12 @@ Additional labels for pre-release (`alpha`, `beta`, `rc`) are available as exten Thanks for everyone [who contributed](https://github.com/fenos/Notifynder/graphs/contributors) to Notifynder and a special thanks for the most active contributors -- [Gummibeer](https://github.com/Gummibeer) \ No newline at end of file +- [Gummibeer](https://github.com/Gummibeer) + +## Services + +* [Travis CI](https://travis-ci.org/fenos/Notifynder) +* [Style CI](https://styleci.io/repos/18425539) +* [Code Climate](https://codeclimate.com/github/fenos/Notifynder) +* [Scrutinizer](https://scrutinizer-ci.com/g/fenos/Notifynder) +* [Coveralls](https://coveralls.io/github/fenos/Notifynder) \ No newline at end of file From 75ffe70dbc93377b09df65483eef98b975296e29 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 12:49:50 +0200 Subject: [PATCH 186/210] try fixing coveralls https://github.com/satooshi/php-coveralls/issues/61 --- .coveralls.yml | 3 ++- .travis.yml | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.coveralls.yml b/.coveralls.yml index 6d00a3d..b81810c 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,2 +1,3 @@ coverage_clover: build/logs/clover.xml -json_path: build/logs/coveralls-upload.json \ No newline at end of file +json_path: build/logs/coveralls-upload.json +service_name: travis-ci \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 4a7bf1d..bfb02c7 100755 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,9 @@ script: after_script: - vendor/bin/test-reporter + - export CI_BUILD_NUMBER="$TRAVIS_BUILD_NUMBER" + - export CI_PULL_REQUEST="$TRAVIS_PULL_REQUEST" + - export CI_BRANCH="$TRAVIS_BRANCH" - vendor/bin/coveralls -v ## Send Build Notifications to Slack From 58de13d83acd8f6470f93cbf04038a0bdaf4f75f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 13:48:02 +0200 Subject: [PATCH 187/210] add even more unittests --- .travis.yml | 2 +- README.md | 15 +++- src/Notifynder/Builder/Notification.php | 10 ++- src/Notifynder/Helpers/helpers.php | 32 +-------- src/Notifynder/Parsers/NotificationParser.php | 30 +++++++- .../Builder/BuilderNotificationTest.php | 66 +++++++++++++++++ tests/integration/Builder/BuilderTest.php | 27 +++++++ tests/integration/Helpers/TypeCheckerTest.php | 70 +++++++++++++------ 8 files changed, 194 insertions(+), 58 deletions(-) create mode 100644 tests/integration/Builder/BuilderNotificationTest.php diff --git a/.travis.yml b/.travis.yml index bfb02c7..d6501dc 100755 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ before_script: ## Run test Scripts script: - vendor/bin/phpunit - - php CoverageChecker.php build/logs/clover.xml 70 + - php CoverageChecker.php build/logs/clover.xml 75 after_script: - vendor/bin/test-reporter diff --git a/README.md b/README.md index 899d84c..e3d1c1f 100755 --- a/README.md +++ b/README.md @@ -5,12 +5,13 @@ [![GitHub issues](https://img.shields.io/github/issues/fenos/Notifynder.svg?style=flat-square)](https://github.com/fenos/Notifynder/issues) [![Total Downloads](https://img.shields.io/packagist/dt/fenos/notifynder.svg?style=flat-square)](https://packagist.org/packages/fenos/notifynder) -[![Travis branch](https://img.shields.io/travis/fenos/Notifynder/master.svg?style=flat-square)](https://travis-ci.org/fenos/Notifynder/branches) +[![Travis branch](https://img.shields.io/travis/fenos/Notifynder/master.svg?style=flat-square&label=TravisCI)](https://travis-ci.org/fenos/Notifynder/branches) [![StyleCI](https://styleci.io/repos/18425539/shield)](https://styleci.io/repos/18425539) -[![Scrutinizer Build](https://img.shields.io/scrutinizer/build/g/fenos/Notifynder.svg?style=flat-square)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) +[![Scrutinizer Build](https://img.shields.io/scrutinizer/build/g/fenos/Notifynder.svg?style=flat-square&label=ScrutinizerCI)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) + [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/fenos/Notifynder.svg?style=flat-square)](https://scrutinizer-ci.com/g/fenos/Notifynder/?branch=master) [![Code Climate](https://img.shields.io/codeclimate/github/fenos/Notifynder.svg?style=flat-square)](https://codeclimate.com/github/fenos/Notifynder) -[![Code Climate](https://img.shields.io/codeclimate/issues/github/fenos/Notifynder.svg?style=flat-square)](https://codeclimate.com/github/fenos/Notifynder/issues) +[![Coveralls](https://img.shields.io/coveralls/fenos/Notifynder.svg?style=flat-square)](https://coveralls.io/github/fenos/Notifynder) [![Slack Team](https://img.shields.io/badge/slack-notifynder-orange.svg?style=flat-square)](https://notifynder.slack.com) [![Slack join](https://img.shields.io/badge/slack-join-green.svg?style=social)](https://notifynder.signup.team) @@ -88,6 +89,14 @@ php artisan migrate This Branch isn't ready for any kind of usage! It's development in progress and will bring a whole new code-base for this package. Everyone is welcome to support us or give feedback for the new major version in our Slack Team. +### ToDo + +Tasks we have to do until this version is ready for a stable release: + +* add unittests for parser and models +* decide if we drop the groups + + ## Versioning Starting with `v4.0.0` we are following the [Semantic Versioning Standard](http://semver.org). diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index f1b8124..00453f6 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -157,11 +157,19 @@ public function toDbArray() /** * @return string */ - public function __toString() + public function toString() { return $this->toJson(); } + /** + * @return string + */ + public function __toString() + { + return $this->toString(); + } + /** * @param string $offset * @return bool diff --git a/src/Notifynder/Helpers/helpers.php b/src/Notifynder/Helpers/helpers.php index 0ffba4b..e25eada 100644 --- a/src/Notifynder/Helpers/helpers.php +++ b/src/Notifynder/Helpers/helpers.php @@ -15,34 +15,4 @@ function notifynder_config($key = null, $default = null) return $config->get($key, $default); } -} - -if (! function_exists('notifynder_mixed_get')) { - /** - * @param array|object $object - * @param string $key - * @param null|mixed $default - * @return mixed - */ - function notifynder_mixed_get($object, $key, $default = null) - { - if (is_null($key) || trim($key) == '') { - return ''; - } - foreach (explode('.', $key) as $segment) { - if (is_object($object) && isset($object->{$segment})) { - $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { - $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { - $object = $object->getAttribute($segment); - } elseif (is_array($object) && array_key_exists($segment, $object)) { - $object = array_get($object, $segment, $default); - } else { - return value($default); - } - } - - return $object; - } -} +} \ No newline at end of file diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index ad730df..a56250c 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -33,7 +33,7 @@ public function parse(Notification $notification) }); foreach ($specialValues as $replacer) { - $replace = notifynder_mixed_get($notification, $replacer); + $replace = $this->mixedGet($notification, $replacer); if (empty($replace) && notifynder_config()->isStrict()) { throw new ExtraParamsException("The following [$replacer] param required from your category is missing."); } @@ -72,4 +72,32 @@ protected function replace($body, $valueMatch, $replacer) return $body; } + + /** + * @param array|object $object + * @param string $key + * @param null|mixed $default + * @return mixed + */ + protected function mixedGet($object, $key, $default = null) + { + if (is_null($key) || trim($key) == '') { + return ''; + } + foreach (explode('.', $key) as $segment) { + if (is_object($object) && isset($object->{$segment})) { + $object = $object->{$segment}; + } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { + $object = $object->__get($segment); + } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { + $object = $object->getAttribute($segment); + } elseif (is_array($object) && array_key_exists($segment, $object)) { + $object = array_get($object, $segment, $default); + } else { + return value($default); + } + } + + return $object; + } } diff --git a/tests/integration/Builder/BuilderNotificationTest.php b/tests/integration/Builder/BuilderNotificationTest.php new file mode 100644 index 0000000..fc1dc61 --- /dev/null +++ b/tests/integration/Builder/BuilderNotificationTest.php @@ -0,0 +1,66 @@ +set('foo', 'bar'); + + $this->assertInternalType('array', $notification->attributes()); + $this->assertCount(1, $notification->attributes()); + $this->assertArrayHasKey('foo', $notification->attributes()); + $this->assertTrue($notification->has('foo')); + $this->assertSame('bar', $notification->attribute('foo')); + $this->assertFalse($notification->isValid()); + + $notification->set('category_id', 1); + $notification->set('from_id', 1); + $notification->set('to_id', 2); + + $this->assertTrue($notification->isValid()); + } + + public function testTypeChanger() + { + $notification = new Notification(); + $notification->set('category_id', 1); + $notification->set('from_id', 1); + $notification->set('to_id', 2); + $notification->set('extra', ['foo' => 'bar']); + + $this->assertTrue($notification->isValid()); + $this->assertInternalType('array', $notification->toArray()); + $this->assertInternalType('array', $notification->toArray()['extra']); + $this->assertInternalType('array', $notification->toDbArray()); + $this->assertInternalType('string', $notification->toDbArray()['extra']); + $this->assertJson($notification->toJson()); + $this->assertInternalType('string', $notification->toString()); + $this->assertInternalType('string', (string)$notification); + } + + public function testOverloaded() + { + $notification = new Notification(); + $notification->category_id = 1; + $notification->from_id = 1; + $notification->to_id = 2; + + $this->assertTrue($notification->isValid()); + $this->assertSame(1, $notification->category_id); + $this->assertSame(1, $notification->from_id); + $this->assertSame(2, $notification->to_id); + } + + public function testOffsetMethods() + { + $notification = new Notification(); + $notification->offsetSet('foo', 'bar'); + $this->assertTrue($notification->offsetExists('foo')); + $this->assertSame('bar', $notification->offsetGet('foo')); + $notification->offsetUnset('foo'); + $this->assertFalse($notification->offsetExists('foo')); + } +} \ No newline at end of file diff --git a/tests/integration/Builder/BuilderTest.php b/tests/integration/Builder/BuilderTest.php index 6c2e8b6..04c5a2f 100644 --- a/tests/integration/Builder/BuilderTest.php +++ b/tests/integration/Builder/BuilderTest.php @@ -252,4 +252,31 @@ public function testCreateSingleNotificationWithRequiredField() $this->assertSame(1, $notification->category_id); $this->assertSame('value', $notification->required_field); } + + public function testCreateSingleNotificationWithSplittedEntityData() + { + $builder = new Builder(); + $notification = $builder + ->category(1) + ->from(\Fenos\Tests\Models\User::class, 1) + ->to(\Fenos\Tests\Models\User::class, 2) + ->getNotification(); + + $this->assertInstanceOf(Notification::class, $notification); + $this->assertSame(1, $notification->category_id); + $this->assertSame(1, $notification->from_id); + $this->assertSame(\Fenos\Tests\Models\User::class, $notification->from_type); + $this->assertSame(2, $notification->to_id); + $this->assertSame(\Fenos\Tests\Models\User::class, $notification->to_type); + } + + public function testOffsetMethods() + { + $builder = new Builder(); + $builder->offsetSet('foo', 'bar'); + $this->assertTrue($builder->offsetExists('foo')); + $this->assertSame('bar', $builder->offsetGet('foo')); + $builder->offsetUnset('foo'); + $this->assertFalse($builder->offsetExists('foo')); + } } diff --git a/tests/integration/Helpers/TypeCheckerTest.php b/tests/integration/Helpers/TypeCheckerTest.php index 5a51176..ec60c5d 100644 --- a/tests/integration/Helpers/TypeCheckerTest.php +++ b/tests/integration/Helpers/TypeCheckerTest.php @@ -5,71 +5,99 @@ class TypeCheckerTest extends NotifynderTestCase { - protected $checker; - - public function setUp() + public function testIsString() { - parent::setUp(); - $this->checker = new TypeChecker(); + $this->assertTrue(TypeChecker::isString('hello world')); } - public function testIsString() + public function testIsStringFailStrict() { - $this->assertTrue($this->checker->isString('hello world')); + $this->setExpectedException(InvalidArgumentException::class); + TypeChecker::isString(15); } public function testIsStringFail() { - $this->setExpectedException(InvalidArgumentException::class); - - $this->assertTrue($this->checker->isString(15)); + $this->assertFalse(TypeChecker::isString(15, false)); } public function testIsNumeric() { - $this->assertTrue($this->checker->isNumeric(15)); + $this->assertTrue(TypeChecker::isNumeric(15)); } - public function testIsNumericFail() + public function testIsNumericFailStrict() { $this->setExpectedException(InvalidArgumentException::class); + TypeChecker::isNumeric('hello world'); + } - $this->assertTrue($this->checker->isNumeric('hello world')); + public function testIsNumericFail() + { + $this->assertFalse(TypeChecker::isNumeric('hello world', false)); } public function testIsDate() { - $this->assertTrue($this->checker->isDate(Carbon::now())); + $this->assertTrue(TypeChecker::isDate(Carbon::now())); } - public function testIsDateFail() + public function testIsDateFailStrict() { $this->setExpectedException(InvalidArgumentException::class); + TypeChecker::isDate('hello world'); + } - $this->assertTrue($this->checker->isDate('hello world')); + public function testIsDateFail() + { + $this->assertFalse(TypeChecker::isDate('hello world', false)); } public function testIsArray() { - $this->assertTrue($this->checker->isArray([1, 2, 3])); + $this->assertTrue(TypeChecker::isArray([1, 2, 3])); } - public function testIsArrayFail() + public function testIsArrayFailStrict() { $this->setExpectedException(InvalidArgumentException::class); + TypeChecker::isArray(collect([1,2,3])); + } - $this->assertTrue($this->checker->isArray([])); + public function testIsArrayFail() + { + $this->assertFalse(TypeChecker::isArray(collect([1,2,3]), false)); } public function testIsIterable() { - $this->assertTrue($this->checker->isIterable(collect([1, 2, 3]))); + $this->assertTrue(TypeChecker::isIterable(collect([1, 2, 3]))); + } + + public function testIsIterableFailStrict() + { + $this->setExpectedException(InvalidArgumentException::class); + TypeChecker::isIterable([]); } public function testIsIterableFail() + { + $this->assertFalse(TypeChecker::isIterable([], false)); + } + + public function testIsNotification() + { + $this->assertTrue(TypeChecker::isNotification(new \Fenos\Notifynder\Models\Notification())); + } + + public function testIsNotificationFailStrict() { $this->setExpectedException(InvalidArgumentException::class); + TypeChecker::isNotification([]); + } - $this->assertTrue($this->checker->isIterable([])); + public function testIsNotificationFail() + { + $this->assertFalse(TypeChecker::isNotification([], false)); } } From c8b86319c36f811bed310fd11a669d919b7778f0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 11:48:13 +0000 Subject: [PATCH 188/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Helpers/helpers.php | 2 +- tests/integration/Builder/BuilderNotificationTest.php | 4 ++-- tests/integration/Helpers/TypeCheckerTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Notifynder/Helpers/helpers.php b/src/Notifynder/Helpers/helpers.php index e25eada..3b0ece9 100644 --- a/src/Notifynder/Helpers/helpers.php +++ b/src/Notifynder/Helpers/helpers.php @@ -15,4 +15,4 @@ function notifynder_config($key = null, $default = null) return $config->get($key, $default); } -} \ No newline at end of file +} diff --git a/tests/integration/Builder/BuilderNotificationTest.php b/tests/integration/Builder/BuilderNotificationTest.php index fc1dc61..6aad508 100644 --- a/tests/integration/Builder/BuilderNotificationTest.php +++ b/tests/integration/Builder/BuilderNotificationTest.php @@ -38,7 +38,7 @@ public function testTypeChanger() $this->assertInternalType('string', $notification->toDbArray()['extra']); $this->assertJson($notification->toJson()); $this->assertInternalType('string', $notification->toString()); - $this->assertInternalType('string', (string)$notification); + $this->assertInternalType('string', (string) $notification); } public function testOverloaded() @@ -63,4 +63,4 @@ public function testOffsetMethods() $notification->offsetUnset('foo'); $this->assertFalse($notification->offsetExists('foo')); } -} \ No newline at end of file +} diff --git a/tests/integration/Helpers/TypeCheckerTest.php b/tests/integration/Helpers/TypeCheckerTest.php index ec60c5d..2416b10 100644 --- a/tests/integration/Helpers/TypeCheckerTest.php +++ b/tests/integration/Helpers/TypeCheckerTest.php @@ -61,12 +61,12 @@ public function testIsArray() public function testIsArrayFailStrict() { $this->setExpectedException(InvalidArgumentException::class); - TypeChecker::isArray(collect([1,2,3])); + TypeChecker::isArray(collect([1, 2, 3])); } public function testIsArrayFail() { - $this->assertFalse(TypeChecker::isArray(collect([1,2,3]), false)); + $this->assertFalse(TypeChecker::isArray(collect([1, 2, 3]), false)); } public function testIsIterable() From 5206e872398b6b3b9e85117f7985511ca548841c Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 14:23:28 +0200 Subject: [PATCH 189/210] add even more unittests --- .travis.yml | 2 +- src/Notifynder/Managers/SenderManager.php | 2 +- src/Notifynder/NotifynderServiceProvider.php | 2 +- src/Notifynder/Senders/OnceSender.php | 4 ++-- .../Managers/NotifynderManagerTest.php | 4 ++++ tests/integration/Senders/OnceSenderTest.php | 15 +++++++++++++++ tests/models/FakeModel.php | 9 +++++++++ 7 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 tests/integration/Senders/OnceSenderTest.php create mode 100644 tests/models/FakeModel.php diff --git a/.travis.yml b/.travis.yml index d6501dc..8921694 100755 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ before_script: ## Run test Scripts script: - vendor/bin/phpunit - - php CoverageChecker.php build/logs/clover.xml 75 + - php CoverageChecker.php build/logs/clover.xml 80 after_script: - vendor/bin/test-reporter diff --git a/src/Notifynder/Managers/SenderManager.php b/src/Notifynder/Managers/SenderManager.php index 33d25ad..a189706 100644 --- a/src/Notifynder/Managers/SenderManager.php +++ b/src/Notifynder/Managers/SenderManager.php @@ -94,7 +94,7 @@ public function sendWithCustomSender($name, array $notifications) */ public function __call($name, array $arguments) { - if (isset($arguments[0]) && is_array($arguments[0])) { + if (array_key_exists(0, $arguments) && isset($arguments[0]) && is_array($arguments[0])) { return $this->sendWithCustomSender($name, $arguments[0]); } diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 239f19a..0fa53b7 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -181,7 +181,7 @@ protected function getMigrationFilepath($filename) if (function_exists('database_path')) { return database_path('/migrations/'.$filename); } else { - return base_path('/database/migrations/'.$filename); + return base_path('/database/migrations/'.$filename); // @codeCoverageIgnore } } } diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index 19f8ba8..e5ee0c7 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -64,8 +64,8 @@ protected function getQuery(Notification $notification) ->where('to_id', $notification->to_id) ->where('to_type', $notification->to_type) ->where('category_id', $notification->category_id); - if (isset($notification->extra) && ! empty($notification->extra)) { - $extra = $notification->extra; + $extra = $notification->extra; + if (!is_null($extra) && ! empty($extra)) { if (is_array($extra)) { $extra = json_encode($extra); } diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php index ece9260..dfa8635 100644 --- a/tests/integration/Managers/NotifynderManagerTest.php +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -132,6 +132,7 @@ public function testSendOnceSameNotifications() $sent = $manager->category(1) ->from(1) ->to(2) + ->extra(['foo' => 'bar']) ->sendOnce(); $this->assertTrue($sent); @@ -150,6 +151,7 @@ public function testSendOnceSameNotifications() $sent = $manager->category(1) ->from(1) ->to(2) + ->extra(['foo' => 'bar']) ->sendOnce(); $this->assertTrue($sent); @@ -173,6 +175,7 @@ public function testSendOnceDifferentNotifications() $sent = $manager->category(1) ->from(1) ->to(2) + ->extra(['foo' => 'bar']) ->sendOnce(); $this->assertTrue($sent); @@ -183,6 +186,7 @@ public function testSendOnceDifferentNotifications() $sent = $manager->category(1) ->from(2) ->to(1) + ->extra(['hello' => 'world']) ->sendOnce(); $this->assertTrue($sent); diff --git a/tests/integration/Senders/OnceSenderTest.php b/tests/integration/Senders/OnceSenderTest.php new file mode 100644 index 0000000..c324f00 --- /dev/null +++ b/tests/integration/Senders/OnceSenderTest.php @@ -0,0 +1,15 @@ +set('notification_model', \Fenos\Tests\Models\FakeModel::class); + + $this->setExpectedException(BadMethodCallException::class); + + $manager = app('notifynder.sender'); + $manager->sendOnce([ + new \Fenos\Notifynder\Builder\Notification(), + ]); + } +} \ No newline at end of file diff --git a/tests/models/FakeModel.php b/tests/models/FakeModel.php new file mode 100644 index 0000000..2892b30 --- /dev/null +++ b/tests/models/FakeModel.php @@ -0,0 +1,9 @@ + Date: Fri, 26 Aug 2016 12:23:41 +0000 Subject: [PATCH 190/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Senders/OnceSender.php | 2 +- tests/integration/Senders/OnceSenderTest.php | 3 ++- tests/models/FakeModel.php | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Notifynder/Senders/OnceSender.php b/src/Notifynder/Senders/OnceSender.php index e5ee0c7..176a3b5 100644 --- a/src/Notifynder/Senders/OnceSender.php +++ b/src/Notifynder/Senders/OnceSender.php @@ -65,7 +65,7 @@ protected function getQuery(Notification $notification) ->where('to_type', $notification->to_type) ->where('category_id', $notification->category_id); $extra = $notification->extra; - if (!is_null($extra) && ! empty($extra)) { + if (! is_null($extra) && ! empty($extra)) { if (is_array($extra)) { $extra = json_encode($extra); } diff --git a/tests/integration/Senders/OnceSenderTest.php b/tests/integration/Senders/OnceSenderTest.php index c324f00..ff50928 100644 --- a/tests/integration/Senders/OnceSenderTest.php +++ b/tests/integration/Senders/OnceSenderTest.php @@ -1,4 +1,5 @@ Date: Fri, 26 Aug 2016 14:50:32 +0200 Subject: [PATCH 191/210] [skip ci] update todo --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e3d1c1f..dfb4887 100755 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Tasks we have to do until this version is ready for a stable release: * add unittests for parser and models * decide if we drop the groups +* complete the new documentation ## Versioning From bdf5b5a4fd036f7a5738cfb0eb5a370933e04dfe Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 17:43:25 +0200 Subject: [PATCH 192/210] update category name formatting --- README.md | 1 - .../Models/NotificationCategory.php | 31 ++++++++++------- src/Notifynder/Models/NotificationGroup.php | 33 ------------------- 3 files changed, 20 insertions(+), 45 deletions(-) delete mode 100755 src/Notifynder/Models/NotificationGroup.php diff --git a/README.md b/README.md index dfb4887..22ff13a 100755 --- a/README.md +++ b/README.md @@ -94,7 +94,6 @@ Everyone is welcome to support us or give feedback for the new major version in Tasks we have to do until this version is ready for a stable release: * add unittests for parser and models -* decide if we drop the groups * complete the new documentation diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index a7dcb39..38a9779 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; /** * Class NotificationCategory. @@ -18,13 +19,25 @@ class NotificationCategory extends Model /** * @var array */ - protected $fillable = ['name', 'text']; + protected $fillable = [ + 'name', + 'text', + ]; /** * @var bool */ public $timestamps = false; + public function __construct(array $attributes) + { + $attributes = array_merge([ + 'text' => '', + ], $attributes); + + parent::__construct($attributes); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -36,17 +49,13 @@ public function notifications() return $this->hasMany($model, 'category_id'); } - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ - public function categories() + public function setNameAttribute($value) { - return $this->belongsToMany( - NotificationGroup::class, - 'notifications_categories_in_groups', - 'category_id', - 'group_id' - ); + $parts = explode('.', $value); + foreach($parts as $i => $part) { + $parts[$i] = Str::slug(preg_replace('/[^a-z0-9_]/', '_', strtolower($part)), '_'); + } + $this->attributes['name'] = implode('.', $parts); } /** diff --git a/src/Notifynder/Models/NotificationGroup.php b/src/Notifynder/Models/NotificationGroup.php deleted file mode 100755 index 6c98abe..0000000 --- a/src/Notifynder/Models/NotificationGroup.php +++ /dev/null @@ -1,33 +0,0 @@ -belongsToMany( - NotificationCategory::class, - 'notifications_categories_in_groups', - 'group_id', 'category_id' - ); - } -} From 70f05989b8a8f4e2a03836aba91b244d8d95332e Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 26 Aug 2016 15:43:32 +0000 Subject: [PATCH 193/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Models/NotificationCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 38a9779..2c53976 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -52,7 +52,7 @@ public function notifications() public function setNameAttribute($value) { $parts = explode('.', $value); - foreach($parts as $i => $part) { + foreach ($parts as $i => $part) { $parts[$i] = Str::slug(preg_replace('/[^a-z0-9_]/', '_', strtolower($part)), '_'); } $this->attributes['name'] = implode('.', $parts); From 721c5f532339ba19dad2829a72395c51dc019df4 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 31 Aug 2016 12:45:24 +0200 Subject: [PATCH 194/210] [skip ci] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22ff13a..3ca9e5e 100755 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Fenos\Notifynder\NotifynderServiceProvider::class, ### Step 3 -#### Migration +#### Migration & Config Publish the migration as well as the configuration of notifynder with the following command: From eb84378d9c818d84f049c1c97e178f77c7eb937b Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 31 Aug 2016 10:45:42 +0000 Subject: [PATCH 195/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Collections/Config.php | 1 - src/Notifynder/Managers/NotifynderManager.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index 31bf30e..319d32e 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -128,7 +128,6 @@ public function set($key, $value = null) app('config')->set('notifynder.'.$key, $value); } - public function reload() { $this->items = app('config')->get('notifynder'); diff --git a/src/Notifynder/Managers/NotifynderManager.php b/src/Notifynder/Managers/NotifynderManager.php index c548745..e8aaecb 100755 --- a/src/Notifynder/Managers/NotifynderManager.php +++ b/src/Notifynder/Managers/NotifynderManager.php @@ -90,7 +90,6 @@ public function sender() return $this->sender; } - protected function reset() { $this->builder = null; From 14a20a18567f549755eb97d60daf3dc6044e569c Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 31 Aug 2016 12:45:50 +0200 Subject: [PATCH 196/210] [skip ci] remove changelog --- change.log | 60 ------------------------------------------------------ 1 file changed, 60 deletions(-) delete mode 100755 change.log diff --git a/change.log b/change.log deleted file mode 100755 index 0b8699b..0000000 --- a/change.log +++ /dev/null @@ -1,60 +0,0 @@ -Notifynder v. 3.0 Change log: - -- Rewrote every UnitTest in PhpSpec - -- Rewrote Main classes with TDD and PHPSpec - -- Rewrote integration test with better organisation and examples - -- Added foreign key to the category_id in notification table / Migration. - -- Compact configuration in one unique file app/config/notifynder.php - -- Added Contracts. It follow the way of laravel 5, each main class has their own contracts - it will be useful to remove encapsulation and to overwtire implementations through IoC - -- Optimization NotifynderBuilder, it doesn't use reflection any more to build the array. - i felt weird that I used reflection for generate an array ( now more fast). - - - Renamed method getArray() in toArray() of the builder - -- Renamed NotifynderNotification to NotifynderManager and extracted it to an interface - with the previous name of the class "NotifynderNotification" - -- Rename NotifynderCategory to CategoryManager and extract it functionalities to an interface - called as the previous class "NotifynderCategory" - -- Translations are now cached on the folder storage/app/notifynder - -- Renamed NotifynderTranslator to TranslatorManager with interface NotifynderTranslator - -- Notifynder Senders can now be extended! You can create your custom Senders. - -- Improvement Notifynder Dispatcher/Handler, - - - Rename the Dispatcher to be Handler (More consistent name) - - Rename the Handler to be Dispatcher (More consistent name) - - The Handler doesn't receive arrays any more but NotifynderEvent object - - Get extra data from the NotifynderEvent Object $event->get('name'), $event->name - - Events are now registered under the Notifynder.* wildcard - - Events can be called with . or @ convention ex: user.registerd - user@registered - - Listeners are defined in the EventServiceProvider with a different property, ex. $notifications - and those listeners are booted with Notifynder::bootListeners($this->notifications) - -- Removed queue system at the moment, I want to think something cool for it, using - The way of laravel 5 will be implemented in notifynder v 3.1.0 - -- fixed method on issue: https://github.com/fenos/Notifynder/issues/22 - -- Added order be date when retrieving notifications, issue: https://github.com/fenos/Notifynder/issues/19 - -- Builder is now part of the Notifynder class, you can access to the builder directly from the Notifynder - class and you can chain your custom and default method for send the notification! Cool! - -- You can now compose and send your notification in one go! - -- Improved EventHandler to be working with a native way of using events - in Laravel 5 - -- No need queue anymore, You can use Laravel ShouldBeQueue - Interface in your events! \ No newline at end of file From 4549b3fd9e8664d365654334bb9b0b4a56e3058f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 16 Sep 2016 14:26:09 +0200 Subject: [PATCH 197/210] #213 add laravel 5.3 support --- .travis.yml | 1 + src/Notifynder/Traits/Notifable.php | 126 +--------------- src/Notifynder/Traits/NotifableBasic.php | 142 +++++++++++++++++++ src/Notifynder/Traits/NotifableLaravel53.php | 30 ++++ tests/NotifynderTestCase.php | 21 ++- tests/integration/Traits/NotifableTest.php | 12 +- tests/models/Car.php | 2 + tests/models/CarL53.php | 19 +++ tests/models/User.php | 2 + tests/models/UserL53.php | 19 +++ 10 files changed, 243 insertions(+), 131 deletions(-) create mode 100755 src/Notifynder/Traits/NotifableBasic.php create mode 100755 src/Notifynder/Traits/NotifableLaravel53.php create mode 100644 tests/models/CarL53.php create mode 100644 tests/models/UserL53.php diff --git a/.travis.yml b/.travis.yml index 8921694..a8ea0b4 100755 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ env: - LARAVEL_VERSION="5.0.*" - LARAVEL_VERSION="5.1.*" - LARAVEL_VERSION="5.2.*" + - LARAVEL_VERSION="5.3.*" ## Install Dependencies install: diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index d673599..1025266 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -2,13 +2,12 @@ namespace Fenos\Notifynder\Traits; -use Fenos\Notifynder\Helpers\TypeChecker; - /** * Class Notifable. */ trait Notifable { + use NotifableBasic; /** * Get the notifications Relationship. * @@ -24,127 +23,8 @@ public function notifications() return $this->hasMany($model, 'to_id'); } - /** - * Get a new NotifynderManager instance with the given category. - * - * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category - * @return \Fenos\Notifynder\Managers\NotifynderManager - */ - public function notifynder($category) - { - return app('notifynder')->category($category); - } - - /** - * Get a new NotifynderManager instance with the given category and $this as the sender. - * - * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category - * @return \Fenos\Notifynder\Managers\NotifynderManager - */ - public function sendNotificationFrom($category) - { - return $this->notifynder($category)->from($this); - } - - /** - * Get a new NotifynderManager instance with the given category and $this as the receiver. - * - * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category - * @return \Fenos\Notifynder\Managers\NotifynderManager - */ - public function sendNotificationTo($category) - { - return $this->notifynder($category)->to($this); - } - - /** - * Read a single Notification. - * - * @param int $notification - * @return bool - */ - public function readNotification($notification) - { - return $this->updateSingleReadStatus($notification, 1); - } - - /** - * Unread a single Notification. - * - * @param int $notification - * @return bool - */ - public function unreadNotification($notification) + public function getNotificationRelation() { - return $this->updateSingleReadStatus($notification, 0); - } - - /** - * @param int $notification - * @param int $value - * @return bool - */ - protected function updateSingleReadStatus($notification, $value) - { - if (! TypeChecker::isNotification($notification, false)) { - $notification = $this->notifications()->findOrFail($notification); - } - - if ($this->notifications()->where($notification->getKeyName(), $notification->getKey())->exists()) { - if ($value) { - return $notification->read(); - } else { - return $notification->unread(); - } - } - - return false; - } - - /** - * Read all Notifications. - * - * @return mixed - */ - public function readAllNotifications() - { - return $this->notifications()->update(['read' => 1]); - } - - /** - * Unread all Notifications. - * - * @return mixed - */ - public function unreadAllNotifications() - { - return $this->notifications()->update(['read' => 0]); - } - - /** - * Count unread notifications. - * - * @return int - */ - public function countUnreadNotifications() - { - return $this->notifications()->byRead(0)->count(); - } - - /** - * Get all Notifications ordered by creation and optional limit. - * - * @param null|int $limit - * @param string $order - * @return \Illuminate\Database\Eloquent\Collection - */ - public function getNotifications($limit = null, $order = 'desc') - { - $query = $this->notifications()->orderBy('created_at', $order); - if (! is_null($limit)) { - $query->limit($limit); - } - - return $query->get(); + return $this->notifications(); } } diff --git a/src/Notifynder/Traits/NotifableBasic.php b/src/Notifynder/Traits/NotifableBasic.php new file mode 100755 index 0000000..c0b951a --- /dev/null +++ b/src/Notifynder/Traits/NotifableBasic.php @@ -0,0 +1,142 @@ +category($category); + } + + /** + * Get a new NotifynderManager instance with the given category and $this as the sender. + * + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return \Fenos\Notifynder\Managers\NotifynderManager + */ + public function sendNotificationFrom($category) + { + return $this->notifynder($category)->from($this); + } + + /** + * Get a new NotifynderManager instance with the given category and $this as the receiver. + * + * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category + * @return \Fenos\Notifynder\Managers\NotifynderManager + */ + public function sendNotificationTo($category) + { + return $this->notifynder($category)->to($this); + } + + /** + * Read a single Notification. + * + * @param int $notification + * @return bool + */ + public function readNotification($notification) + { + return $this->updateSingleReadStatus($notification, 1); + } + + /** + * Unread a single Notification. + * + * @param int $notification + * @return bool + */ + public function unreadNotification($notification) + { + return $this->updateSingleReadStatus($notification, 0); + } + + /** + * @param int $notification + * @param int $value + * @return bool + */ + protected function updateSingleReadStatus($notification, $value) + { + if (! TypeChecker::isNotification($notification, false)) { + $notification = $this->getNotificationRelation()->findOrFail($notification); + } + + if ($this->getNotificationRelation()->where($notification->getKeyName(), $notification->getKey())->exists()) { + if ($value) { + return $notification->read(); + } else { + return $notification->unread(); + } + } + + return false; + } + + /** + * Read all Notifications. + * + * @return mixed + */ + public function readAllNotifications() + { + return $this->getNotificationRelation()->update(['read' => 1]); + } + + /** + * Unread all Notifications. + * + * @return mixed + */ + public function unreadAllNotifications() + { + return $this->getNotificationRelation()->update(['read' => 0]); + } + + /** + * Count unread notifications. + * + * @return int + */ + public function countUnreadNotifications() + { + return $this->getNotificationRelation()->byRead(0)->count(); + } + + /** + * Get all Notifications ordered by creation and optional limit. + * + * @param null|int $limit + * @param string $order + * @return \Illuminate\Database\Eloquent\Collection + */ + public function getNotifications($limit = null, $order = 'desc') + { + $query = $this->getNotificationRelation()->orderBy('created_at', $order); + if (! is_null($limit)) { + $query->limit($limit); + } + + return $query->get(); + } +} diff --git a/src/Notifynder/Traits/NotifableLaravel53.php b/src/Notifynder/Traits/NotifableLaravel53.php new file mode 100755 index 0000000..f5f6da8 --- /dev/null +++ b/src/Notifynder/Traits/NotifableLaravel53.php @@ -0,0 +1,30 @@ +getNotificationModel(); + if (notifynder_config()->isPolymorphic()) { + return $this->morphMany($model, 'to'); + } + + return $this->hasMany($model, 'to_id'); + } + + public function getNotificationRelation() + { + return $this->notifynderNotifications(); + } +} diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index 5c5a401..9755454 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -2,7 +2,9 @@ use Orchestra\Testbench\TestCase as OrchestraTestCase; use Fenos\Tests\Models\User; +use Fenos\Tests\Models\UserL53; use Fenos\Tests\Models\Car; +use Fenos\Tests\Models\CarL53; use Fenos\Notifynder\NotifynderServiceProvider; use Fenos\Notifynder\Facades\Notifynder as NotifynderFacade; use Illuminate\Database\Eloquent\Model; @@ -71,7 +73,11 @@ protected function createUser(array $attributes = []) 'lastname' => 'Doe', ], $attributes); - return User::create($attributes); + if($this->getLaravelVersion() < 5.3) { + return User::create($attributes); + } else { + return UserL53::create($attributes); + } } protected function createCar(array $attributes = []) @@ -81,7 +87,11 @@ protected function createCar(array $attributes = []) 'model' => 'A6', ], $attributes); - return Car::create($attributes); + if($this->getLaravelVersion() < 5.3) { + return Car::create($attributes); + } else { + return CarL53::create($attributes); + } } protected function sendNotificationTo(Model $model) @@ -99,4 +109,11 @@ protected function sendNotificationsTo(Model $model, $amount = 10) $amount--; } } + + protected function getLaravelVersion() + { + $version = app()::VERSION; + $parts = explode('.', $version); + return ($parts[0].'.'.$parts[1]) * 1; + } } diff --git a/tests/integration/Traits/NotifableTest.php b/tests/integration/Traits/NotifableTest.php index 470c3e3..fd8c728 100644 --- a/tests/integration/Traits/NotifableTest.php +++ b/tests/integration/Traits/NotifableTest.php @@ -46,7 +46,7 @@ public function testSendNotificationTo() $this->assertSame(1, $notification->category_id); $this->assertSame(1, $notification->to_id); $notifynder->send(); - $this->assertCount(1, $user->notifications); + $this->assertCount(1, $user->getNotificationRelation); } public function testNotificationsHasMany() @@ -56,7 +56,7 @@ public function testNotificationsHasMany() ->sendNotificationTo(1) ->from(2) ->send(); - $this->assertCount(1, $user->notifications); + $this->assertCount(1, $user->getNotificationRelation); } public function testNotificationsMorphMany() @@ -67,8 +67,8 @@ public function testNotificationsMorphMany() $this->sendNotificationTo($user); $car = $this->createCar(); $this->sendNotificationTo($car); - $this->assertCount(1, $user->notifications); - $this->assertCount(1, $car->notifications); + $this->assertCount(1, $user->getNotificationRelation); + $this->assertCount(1, $car->getNotificationRelation); } public function testGetNotificationsDefault() @@ -94,7 +94,7 @@ public function testReadStatusRelatedMethods() $this->assertSame(0, $user->countUnreadNotifications()); $this->assertSame(25, $user->unreadAllNotifications()); $this->assertSame(25, $user->countUnreadNotifications()); - $notification = $user->notifications->first(); + $notification = $user->getNotificationRelation->first(); $this->assertTrue($user->readNotification($notification)); $this->assertSame(24, $user->countUnreadNotifications()); $this->assertTrue($user->unreadNotification($notification->getKey())); @@ -103,6 +103,6 @@ public function testReadStatusRelatedMethods() $user2 = $this->createUser(); $this->sendNotificationsTo($user2, 5); - $this->assertFalse($user->readNotification($user2->notifications()->first())); + $this->assertFalse($user->readNotification($user2->getNotificationRelation->first())); } } diff --git a/tests/models/Car.php b/tests/models/Car.php index 743af5e..694e8fd 100644 --- a/tests/models/Car.php +++ b/tests/models/Car.php @@ -9,6 +9,8 @@ class Car extends Model { use Notifable; + protected $table = 'cars'; + protected $fillable = [ 'id', 'brand', diff --git a/tests/models/CarL53.php b/tests/models/CarL53.php new file mode 100644 index 0000000..afd824c --- /dev/null +++ b/tests/models/CarL53.php @@ -0,0 +1,19 @@ + Date: Fri, 16 Sep 2016 12:26:19 +0000 Subject: [PATCH 198/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Traits/Notifable.php | 1 + src/Notifynder/Traits/NotifableLaravel53.php | 1 + tests/NotifynderTestCase.php | 5 +++-- tests/models/CarL53.php | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 1025266..e352866 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -8,6 +8,7 @@ trait Notifable { use NotifableBasic; + /** * Get the notifications Relationship. * diff --git a/src/Notifynder/Traits/NotifableLaravel53.php b/src/Notifynder/Traits/NotifableLaravel53.php index f5f6da8..09328b1 100755 --- a/src/Notifynder/Traits/NotifableLaravel53.php +++ b/src/Notifynder/Traits/NotifableLaravel53.php @@ -8,6 +8,7 @@ trait NotifableLaravel53 { use NotifableBasic; + /** * Get the notifications Relationship. * diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index 9755454..f93766e 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -73,7 +73,7 @@ protected function createUser(array $attributes = []) 'lastname' => 'Doe', ], $attributes); - if($this->getLaravelVersion() < 5.3) { + if ($this->getLaravelVersion() < 5.3) { return User::create($attributes); } else { return UserL53::create($attributes); @@ -87,7 +87,7 @@ protected function createCar(array $attributes = []) 'model' => 'A6', ], $attributes); - if($this->getLaravelVersion() < 5.3) { + if ($this->getLaravelVersion() < 5.3) { return Car::create($attributes); } else { return CarL53::create($attributes); @@ -114,6 +114,7 @@ protected function getLaravelVersion() { $version = app()::VERSION; $parts = explode('.', $version); + return ($parts[0].'.'.$parts[1]) * 1; } } diff --git a/tests/models/CarL53.php b/tests/models/CarL53.php index afd824c..4bbc8d1 100644 --- a/tests/models/CarL53.php +++ b/tests/models/CarL53.php @@ -10,7 +10,7 @@ class CarL53 extends Model use NotifableLaravel53; protected $table = 'cars'; - + protected $fillable = [ 'id', 'brand', From 41578e69baacdaea2b3ade0947c3fe7aa1e5042a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 16 Sep 2016 14:36:54 +0200 Subject: [PATCH 199/210] fix php syntax error --- tests/NotifynderTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index f93766e..cc61ef2 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -112,7 +112,7 @@ protected function sendNotificationsTo(Model $model, $amount = 10) protected function getLaravelVersion() { - $version = app()::VERSION; + $version = app()->version(); $parts = explode('.', $version); return ($parts[0].'.'.$parts[1]) * 1; From 9f7ef03f9321935b1cf54ac925d3ac24e1357066 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 16 Sep 2016 16:04:22 +0200 Subject: [PATCH 200/210] fix php version and laravel 5.3 conflict --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index a8ea0b4..a8c9834 100755 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,11 @@ env: - LARAVEL_VERSION="5.2.*" - LARAVEL_VERSION="5.3.*" +matrix: + exclude: + - php: 5.5 + env: LARAVEL_VERSION="5.3.*" + ## Install Dependencies install: - composer self-update From 3da719148a30632493ceda4d52eed487578a8311 Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Thu, 29 Sep 2016 18:13:51 +0100 Subject: [PATCH 201/210] Invalid constructor Not always array is given whe model is being created, therefore we need to add this. Error: Type error: Argument 1 passed to Fenos\Notifynder\Models\NotificationCategory::__construct() must be of the type array, none given, called in --- src/Notifynder/Models/NotificationCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 2c53976..76b6e08 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -29,7 +29,7 @@ class NotificationCategory extends Model */ public $timestamps = false; - public function __construct(array $attributes) + public function __construct(array $attributes = []) { $attributes = array_merge([ 'text' => '', From 645cd0d5483bacf5f54e5f20f7152c1d9c704a74 Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Thu, 27 Oct 2016 18:33:50 +0100 Subject: [PATCH 202/210] Allow to use custom model for Single Sender --- src/Notifynder/Senders/SingleSender.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Notifynder/Senders/SingleSender.php b/src/Notifynder/Senders/SingleSender.php index d4ef585..190a4fa 100644 --- a/src/Notifynder/Senders/SingleSender.php +++ b/src/Notifynder/Senders/SingleSender.php @@ -34,8 +34,10 @@ public function __construct(array $notifications) */ public function send(SenderManagerContract $sender) { - $notification = new Notification($this->notification); + $model = notifynder_config()->getNotificationModel(); + $notification = new $model($this->notification); + return $notification->save(); } } From 966448865156e608c73ff70b1dc4822a4f4dc228 Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Thu, 27 Oct 2016 18:36:38 +0100 Subject: [PATCH 203/210] Fix CI --- src/Notifynder/Senders/SingleSender.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notifynder/Senders/SingleSender.php b/src/Notifynder/Senders/SingleSender.php index 190a4fa..7e3b17b 100644 --- a/src/Notifynder/Senders/SingleSender.php +++ b/src/Notifynder/Senders/SingleSender.php @@ -37,7 +37,7 @@ public function send(SenderManagerContract $sender) $model = notifynder_config()->getNotificationModel(); $notification = new $model($this->notification); - + return $notification->save(); } } From d4d6c888700b0d543c75bfcd79c2f921272154d2 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 28 Oct 2016 14:28:04 +0200 Subject: [PATCH 204/210] update slack team name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ca9e5e..ed1a88f 100755 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![Code Climate](https://img.shields.io/codeclimate/github/fenos/Notifynder.svg?style=flat-square)](https://codeclimate.com/github/fenos/Notifynder) [![Coveralls](https://img.shields.io/coveralls/fenos/Notifynder.svg?style=flat-square)](https://coveralls.io/github/fenos/Notifynder) -[![Slack Team](https://img.shields.io/badge/slack-notifynder-orange.svg?style=flat-square)](https://notifynder.slack.com) +[![Slack Team](https://img.shields.io/badge/slack-astrotomic-orange.svg?style=flat-square)](https://astrotomic.slack.com) [![Slack join](https://img.shields.io/badge/slack-join-green.svg?style=social)](https://notifynder.signup.team) From 897627f1e46fc28e59a4b06c98ebd8be74fcf171 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 2 Nov 2016 10:38:30 +0100 Subject: [PATCH 205/210] #222 drop unused tables `notifications_groups` & `notifications_categories_in_groups` --- src/Notifynder/NotifynderServiceProvider.php | 1 + ...4_02_10_145728_notification_categories.php | 2 +- ...10813_create_notification_groups_table.php | 2 +- ...tion_category_notification_group_table.php | 2 +- ...5_05_212549_create_notifications_table.php | 2 +- ..._02_193415_drop_version4_unused_tables.php | 28 +++++++++++++++++++ 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/migrations/2016_11_02_193415_drop_version4_unused_tables.php diff --git a/src/Notifynder/NotifynderServiceProvider.php b/src/Notifynder/NotifynderServiceProvider.php index 0fa53b7..1b2cf0b 100755 --- a/src/Notifynder/NotifynderServiceProvider.php +++ b/src/Notifynder/NotifynderServiceProvider.php @@ -29,6 +29,7 @@ class NotifynderServiceProvider extends ServiceProvider 'MakeNotificationUrlNullable' => '2016_04_19_200827_make_notification_url_nullable', 'AddStackIdToNotifications' => '2016_05_19_144531_add_stack_id_to_notifications', 'UpdateVersion4NotificationsTable' => '2016_07_01_153156_update_version4_notifications_table', + 'DropVersion4UnusedTables' => '2016_11_02_193415_drop_version4_unused_tables', ]; /** diff --git a/src/migrations/2014_02_10_145728_notification_categories.php b/src/migrations/2014_02_10_145728_notification_categories.php index b58b7cd..94893d6 100755 --- a/src/migrations/2014_02_10_145728_notification_categories.php +++ b/src/migrations/2014_02_10_145728_notification_categories.php @@ -26,6 +26,6 @@ public function up() */ public function down() { - Schema::drop('notification_categories'); + Schema::dropIfExists('notification_categories'); } } diff --git a/src/migrations/2014_08_01_210813_create_notification_groups_table.php b/src/migrations/2014_08_01_210813_create_notification_groups_table.php index d048a59..e0bed21 100755 --- a/src/migrations/2014_08_01_210813_create_notification_groups_table.php +++ b/src/migrations/2014_08_01_210813_create_notification_groups_table.php @@ -25,6 +25,6 @@ public function up() */ public function down() { - Schema::drop('notification_groups'); + Schema::dropIfExists('notification_groups'); } } diff --git a/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php b/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php index 7b243f7..5475c63 100755 --- a/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php +++ b/src/migrations/2014_08_01_211045_create_notification_category_notification_group_table.php @@ -28,6 +28,6 @@ public function up() */ public function down() { - Schema::drop('notifications_categories_in_groups'); + Schema::dropIfExists('notifications_categories_in_groups'); } } diff --git a/src/migrations/2015_05_05_212549_create_notifications_table.php b/src/migrations/2015_05_05_212549_create_notifications_table.php index 90c35c9..76e4638 100755 --- a/src/migrations/2015_05_05_212549_create_notifications_table.php +++ b/src/migrations/2015_05_05_212549_create_notifications_table.php @@ -36,6 +36,6 @@ public function up() */ public function down() { - Schema::drop('notifications'); + Schema::dropIfExists('notifications'); } } diff --git a/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php b/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php new file mode 100644 index 0000000..5881b67 --- /dev/null +++ b/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php @@ -0,0 +1,28 @@ + Date: Wed, 2 Nov 2016 09:38:40 +0000 Subject: [PATCH 206/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/migrations/2016_11_02_193415_drop_version4_unused_tables.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php b/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php index 5881b67..b0af3a7 100644 --- a/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php +++ b/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php @@ -1,6 +1,5 @@ Date: Wed, 16 Nov 2016 14:30:10 +0100 Subject: [PATCH 207/210] add phpDoc blocks --- src/Notifynder/Collections/Config.php | 5 ++++- src/Notifynder/Contracts/ConfigContract.php | 2 -- .../Contracts/NotifynderManagerContract.php | 3 +++ src/Notifynder/Exceptions/ExtraParamsException.php | 3 +++ .../Exceptions/UnvalidNotificationException.php | 13 +++++++++++++ src/Notifynder/Facades/Notifynder.php | 6 ++++++ src/Notifynder/Traits/Notifable.php | 7 ++++++- src/Notifynder/Traits/NotifableLaravel53.php | 5 +++++ .../2014_02_10_145728_notification_categories.php | 2 +- 9 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index 319d32e..8ba5d4b 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -120,7 +120,7 @@ public function has($key) /** * @param string $key - * @param null|mixed $value + * @param null $value */ public function set($key, $value = null) { @@ -128,6 +128,9 @@ public function set($key, $value = null) app('config')->set('notifynder.'.$key, $value); } + /** + * + */ public function reload() { $this->items = app('config')->get('notifynder'); diff --git a/src/Notifynder/Contracts/ConfigContract.php b/src/Notifynder/Contracts/ConfigContract.php index c03344b..fe4b39b 100644 --- a/src/Notifynder/Contracts/ConfigContract.php +++ b/src/Notifynder/Contracts/ConfigContract.php @@ -63,7 +63,6 @@ public function has($key); /** * @param string $key * @param mixed $value - * @return mixed */ public function set($key, $value); @@ -76,7 +75,6 @@ public function __get($key); /** * @param string $key * @param mixed $value - * @return mixed */ public function __set($key, $value); } diff --git a/src/Notifynder/Contracts/NotifynderManagerContract.php b/src/Notifynder/Contracts/NotifynderManagerContract.php index 11dd105..f9a335a 100755 --- a/src/Notifynder/Contracts/NotifynderManagerContract.php +++ b/src/Notifynder/Contracts/NotifynderManagerContract.php @@ -4,6 +4,9 @@ use Closure; +/** + * Interface NotifynderManagerContract. + */ interface NotifynderManagerContract { /** diff --git a/src/Notifynder/Exceptions/ExtraParamsException.php b/src/Notifynder/Exceptions/ExtraParamsException.php index ce26243..52c8b2f 100644 --- a/src/Notifynder/Exceptions/ExtraParamsException.php +++ b/src/Notifynder/Exceptions/ExtraParamsException.php @@ -4,6 +4,9 @@ use Exception; +/** + * Class ExtraParamsException + */ class ExtraParamsException extends Exception { } diff --git a/src/Notifynder/Exceptions/UnvalidNotificationException.php b/src/Notifynder/Exceptions/UnvalidNotificationException.php index 33a067a..28963ab 100644 --- a/src/Notifynder/Exceptions/UnvalidNotificationException.php +++ b/src/Notifynder/Exceptions/UnvalidNotificationException.php @@ -5,10 +5,20 @@ use Exception; use Fenos\Notifynder\Builder\Notification; +/** + * Class UnvalidNotificationException + */ class UnvalidNotificationException extends Exception { + /** + * @var Notification + */ public $notification; + /** + * UnvalidNotificationException constructor. + * @param Notification $notification + */ public function __construct(Notification $notification) { parent::__construct('The given data failed to pass validation.'); @@ -16,6 +26,9 @@ public function __construct(Notification $notification) $this->notification = $notification; } + /** + * @return Notification + */ public function getNotification() { return $this->notification; diff --git a/src/Notifynder/Facades/Notifynder.php b/src/Notifynder/Facades/Notifynder.php index 0e14d74..acadbf5 100644 --- a/src/Notifynder/Facades/Notifynder.php +++ b/src/Notifynder/Facades/Notifynder.php @@ -4,8 +4,14 @@ use Illuminate\Support\Facades\Facade; +/** + * Class Notifynder + */ class Notifynder extends Facade { + /** + * @return string + */ protected static function getFacadeAccessor() { return 'notifynder'; diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index e352866..1c0d0dc 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -3,7 +3,7 @@ namespace Fenos\Notifynder\Traits; /** - * Class Notifable. + * Class Notifable */ trait Notifable { @@ -24,6 +24,11 @@ public function notifications() return $this->hasMany($model, 'to_id'); } + /** + * Get the notifications Relationship. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany + */ public function getNotificationRelation() { return $this->notifications(); diff --git a/src/Notifynder/Traits/NotifableLaravel53.php b/src/Notifynder/Traits/NotifableLaravel53.php index 09328b1..707f78e 100755 --- a/src/Notifynder/Traits/NotifableLaravel53.php +++ b/src/Notifynder/Traits/NotifableLaravel53.php @@ -24,6 +24,11 @@ public function notifynderNotifications() return $this->hasMany($model, 'to_id'); } + /** + * Get the notifications Relationship. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany + */ public function getNotificationRelation() { return $this->notifynderNotifications(); diff --git a/src/migrations/2014_02_10_145728_notification_categories.php b/src/migrations/2014_02_10_145728_notification_categories.php index 94893d6..df0d475 100755 --- a/src/migrations/2014_02_10_145728_notification_categories.php +++ b/src/migrations/2014_02_10_145728_notification_categories.php @@ -7,7 +7,7 @@ class NotificationCategories extends Migration { /** * Run the migrations. - * + * @return void */ public function up() From c8c33dac11451f5ad38e63d137be936db56b83b0 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 16 Nov 2016 13:30:21 +0000 Subject: [PATCH 208/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Collections/Config.php | 4 +--- src/Notifynder/Exceptions/ExtraParamsException.php | 2 +- src/Notifynder/Exceptions/UnvalidNotificationException.php | 2 +- src/Notifynder/Facades/Notifynder.php | 2 +- src/Notifynder/Traits/Notifable.php | 2 +- src/migrations/2014_02_10_145728_notification_categories.php | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index 8ba5d4b..48fcd73 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -128,9 +128,7 @@ public function set($key, $value = null) app('config')->set('notifynder.'.$key, $value); } - /** - * - */ + public function reload() { $this->items = app('config')->get('notifynder'); diff --git a/src/Notifynder/Exceptions/ExtraParamsException.php b/src/Notifynder/Exceptions/ExtraParamsException.php index 52c8b2f..2013417 100644 --- a/src/Notifynder/Exceptions/ExtraParamsException.php +++ b/src/Notifynder/Exceptions/ExtraParamsException.php @@ -5,7 +5,7 @@ use Exception; /** - * Class ExtraParamsException + * Class ExtraParamsException. */ class ExtraParamsException extends Exception { diff --git a/src/Notifynder/Exceptions/UnvalidNotificationException.php b/src/Notifynder/Exceptions/UnvalidNotificationException.php index 28963ab..3378e21 100644 --- a/src/Notifynder/Exceptions/UnvalidNotificationException.php +++ b/src/Notifynder/Exceptions/UnvalidNotificationException.php @@ -6,7 +6,7 @@ use Fenos\Notifynder\Builder\Notification; /** - * Class UnvalidNotificationException + * Class UnvalidNotificationException. */ class UnvalidNotificationException extends Exception { diff --git a/src/Notifynder/Facades/Notifynder.php b/src/Notifynder/Facades/Notifynder.php index acadbf5..fae558f 100644 --- a/src/Notifynder/Facades/Notifynder.php +++ b/src/Notifynder/Facades/Notifynder.php @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Facade; /** - * Class Notifynder + * Class Notifynder. */ class Notifynder extends Facade { diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index 1c0d0dc..ddfdc69 100755 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -3,7 +3,7 @@ namespace Fenos\Notifynder\Traits; /** - * Class Notifable + * Class Notifable. */ trait Notifable { diff --git a/src/migrations/2014_02_10_145728_notification_categories.php b/src/migrations/2014_02_10_145728_notification_categories.php index df0d475..0096cb7 100755 --- a/src/migrations/2014_02_10_145728_notification_categories.php +++ b/src/migrations/2014_02_10_145728_notification_categories.php @@ -7,7 +7,7 @@ class NotificationCategories extends Migration { /** * Run the migrations. - + * @return void */ public function up() From c56dd13e52fdd9850c575aec07efa8c4090b8587 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 24 Nov 2016 11:56:35 +0100 Subject: [PATCH 209/210] #229 add `getText()` on the builder notification class --- src/Notifynder/Builder/Notification.php | 13 +++++++++++ src/Notifynder/Models/Notification.php | 19 +-------------- .../Models/NotificationCategory.php | 23 +++++++++++++++++++ src/Notifynder/Parsers/NotificationParser.php | 20 +++++++++------- tests/NotifynderTestCase.php | 11 +++++++++ .../Builder/BuilderNotificationTest.php | 13 +++++++++++ 6 files changed, 73 insertions(+), 26 deletions(-) diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index 00453f6..45300ac 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -3,10 +3,12 @@ namespace Fenos\Notifynder\Builder; use ArrayAccess; +use Fenos\Notifynder\Parsers\NotificationParser; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Support\Arr; use JsonSerializable; +use Fenos\Notifynder\Models\Notification as ModelNotification; /** * Class Notification. @@ -154,6 +156,17 @@ public function toDbArray() return $notification; } + /** + * @return string + */ + public function getText() { + if ($this->isValid()) { + $notification = new ModelNotification($this); + $notifynderParse = new NotificationParser(); + return $notifynderParse->parse($notification, $this->category_id); + } + } + /** * @return string */ diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index a2cfc71..308f048 100755 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -33,7 +33,6 @@ class Notification extends Model */ protected $appends = [ 'text', - 'template_body', ]; /** @@ -109,22 +108,6 @@ protected function mergeFillables() return $fillables; } - /** - * @return string - */ - public function getTemplateBodyAttribute() - { - if (notifynder_config()->isTranslated()) { - $key = notifynder_config()->getTranslationDomain().'.'.$this->category->name; - $trans = trans($key); - if ($trans != $key) { - return $trans; - } - } - - return $this->category->text; - } - /** * @return string * @throws \Fenos\Notifynder\Exceptions\ExtraParamsException @@ -133,7 +116,7 @@ public function getTextAttribute() { if (! array_key_exists('text', $this->attributes)) { $notifynderParse = new NotificationParser(); - $this->attributes['text'] = $notifynderParse->parse($this); + $this->attributes['text'] = $notifynderParse->parse($this, $this->category_id); } return $this->attributes['text']; diff --git a/src/Notifynder/Models/NotificationCategory.php b/src/Notifynder/Models/NotificationCategory.php index 76b6e08..7c660e9 100755 --- a/src/Notifynder/Models/NotificationCategory.php +++ b/src/Notifynder/Models/NotificationCategory.php @@ -24,6 +24,13 @@ class NotificationCategory extends Model 'text', ]; + /** + * @var array + */ + protected $appends = [ + 'template_body', + ]; + /** * @var bool */ @@ -58,6 +65,22 @@ public function setNameAttribute($value) $this->attributes['name'] = implode('.', $parts); } + /** + * @return string + */ + public function getTemplateBodyAttribute() + { + if (notifynder_config()->isTranslated()) { + $key = notifynder_config()->getTranslationDomain().'.'.$this->name; + $trans = trans($key); + if ($trans != $key) { + return $trans; + } + } + + return $this->text; + } + /** * @param Builder $query * @param $name diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index a56250c..f9278b4 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -2,8 +2,10 @@ namespace Fenos\Notifynder\Parsers; +use Fenos\Notifynder\Builder\Notification as BuilderNotification; use Fenos\Notifynder\Exceptions\ExtraParamsException; -use Fenos\Notifynder\Models\Notification; +use Fenos\Notifynder\Models\Notification as ModelNotification; +use Fenos\Notifynder\Models\NotificationCategory; /** * Class NotificationParser. @@ -18,18 +20,20 @@ class NotificationParser /** * Parse a notification and return the body text. * - * @param Notification $notification + * @param array|ModelNotification|BuilderNotification $notification + * @param int $categoryId * @return string * @throws ExtraParamsException */ - public function parse(Notification $notification) + public function parse($notification, $categoryId) { - $text = $notification->template_body; + $category = NotificationCategory::findOrFail($categoryId); + $text = $category->template_body; $specialValues = $this->getValues($text); if (count($specialValues) > 0) { $specialValues = array_filter($specialValues, function ($value) use ($notification) { - return isset($notification->$value) || starts_with($value, ['extra.', 'to.', 'from.']); + return ((is_array($notification) && isset($notification[$value])) || (is_object($notification) && isset($notification->$value))) || starts_with($value, ['extra.', 'to.', 'from.']); }); foreach ($specialValues as $replacer) { @@ -68,7 +72,7 @@ protected function getValues($body) */ protected function replace($body, $valueMatch, $replacer) { - $body = str_replace('{'.$replacer.'}', $valueMatch, $body); + $body = str_replace('{' . $replacer . '}', $valueMatch, $body); return $body; } @@ -87,9 +91,9 @@ protected function mixedGet($object, $key, $default = null) foreach (explode('.', $key) as $segment) { if (is_object($object) && isset($object->{$segment})) { $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { + } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { + } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { $object = $object->getAttribute($segment); } elseif (is_array($object) && array_key_exists($segment, $object)) { $object = array_get($object, $segment, $default); diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index cc61ef2..dba5dd0 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -8,6 +8,7 @@ use Fenos\Notifynder\NotifynderServiceProvider; use Fenos\Notifynder\Facades\Notifynder as NotifynderFacade; use Illuminate\Database\Eloquent\Model; +use Fenos\Notifynder\Models\NotificationCategory; abstract class NotifynderTestCase extends OrchestraTestCase { @@ -66,6 +67,16 @@ protected function migrate($artisan, $path = '/../../../../src/migrations') ]); } + protected function createCategory(array $attributes = []) + { + $attributes = array_merge([ + 'text' => 'Notification send from #{from.id} to #{to.id}.', + 'name' => 'test.category', + ], $attributes); + + return NotificationCategory::create($attributes); + } + protected function createUser(array $attributes = []) { $attributes = array_merge([ diff --git a/tests/integration/Builder/BuilderNotificationTest.php b/tests/integration/Builder/BuilderNotificationTest.php index 6aad508..92229e6 100644 --- a/tests/integration/Builder/BuilderNotificationTest.php +++ b/tests/integration/Builder/BuilderNotificationTest.php @@ -63,4 +63,17 @@ public function testOffsetMethods() $notification->offsetUnset('foo'); $this->assertFalse($notification->offsetExists('foo')); } + + public function testGetText() + { + $category = $this->createCategory(); + $from = $this->createUser(); + $to = $this->createUser(); + $notification = new Notification(); + $notification->set('category_id', $category->getKey()); + $notification->set('from_id', $from->getKey()); + $notification->set('to_id', $to->getKey()); + + $this->assertSame('Notification send from #1 to #2.', $notification->getText()); + } } From e8b344a3327caff3550beaa26d799307c5931519 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Thu, 24 Nov 2016 10:56:50 +0000 Subject: [PATCH 210/210] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Notifynder/Builder/Notification.php | 4 +++- src/Notifynder/Collections/Config.php | 1 - src/Notifynder/Parsers/NotificationParser.php | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Notifynder/Builder/Notification.php b/src/Notifynder/Builder/Notification.php index 45300ac..f790911 100644 --- a/src/Notifynder/Builder/Notification.php +++ b/src/Notifynder/Builder/Notification.php @@ -159,10 +159,12 @@ public function toDbArray() /** * @return string */ - public function getText() { + public function getText() + { if ($this->isValid()) { $notification = new ModelNotification($this); $notifynderParse = new NotificationParser(); + return $notifynderParse->parse($notification, $this->category_id); } } diff --git a/src/Notifynder/Collections/Config.php b/src/Notifynder/Collections/Config.php index 48fcd73..1371033 100644 --- a/src/Notifynder/Collections/Config.php +++ b/src/Notifynder/Collections/Config.php @@ -128,7 +128,6 @@ public function set($key, $value = null) app('config')->set('notifynder.'.$key, $value); } - public function reload() { $this->items = app('config')->get('notifynder'); diff --git a/src/Notifynder/Parsers/NotificationParser.php b/src/Notifynder/Parsers/NotificationParser.php index f9278b4..b345b03 100644 --- a/src/Notifynder/Parsers/NotificationParser.php +++ b/src/Notifynder/Parsers/NotificationParser.php @@ -72,7 +72,7 @@ protected function getValues($body) */ protected function replace($body, $valueMatch, $replacer) { - $body = str_replace('{' . $replacer . '}', $valueMatch, $body); + $body = str_replace('{'.$replacer.'}', $valueMatch, $body); return $body; } @@ -91,9 +91,9 @@ protected function mixedGet($object, $key, $default = null) foreach (explode('.', $key) as $segment) { if (is_object($object) && isset($object->{$segment})) { $object = $object->{$segment}; - } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) { + } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { $object = $object->__get($segment); - } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) { + } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { $object = $object->getAttribute($segment); } elseif (is_array($object) && array_key_exists($segment, $object)) { $object = array_get($object, $segment, $default);