Skip to content

Commit 3b7ee19

Browse files
authored
Merge pull request #58 from GetStream/fix/cs
Code Style cleanup
2 parents aa6f2f8 + cd025c5 commit 3b7ee19

16 files changed

+208
-146
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<?php namespace GetStream\StreamLaravel\Eloquent;
1+
<?php
22

3-
use \Illuminate\Database\Eloquent\Model;
3+
namespace GetStream\StreamLaravel\Eloquent;
44

5-
abstract class Activity extends Model {
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
abstract class Activity extends Model
8+
{
69
use ActivityTrait;
710
}

src/GetStream/StreamLaravel/Eloquent/ActivityTrait.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public function activityActorId()
6060

6161
/**
6262
* The reference to the model instance of the author/owner
63-
* @return object \Illuminate\Database\Eloquent\Model instance
63+
*
64+
* @return string
6465
*/
6566
public function activityActor()
6667
{
@@ -80,6 +81,7 @@ public function activityVerb()
8081

8182
/**
8283
* The activity object for this instance
84+
*
8385
* @return string
8486
*/
8587
public function activityObject()
@@ -89,6 +91,7 @@ public function activityObject()
8991

9092
/**
9193
* The activity foreign_id for this instance
94+
*
9295
* @return string
9396
*/
9497
public function activityForeignId()
@@ -98,6 +101,7 @@ public function activityForeignId()
98101

99102
/**
100103
* The activity time for this instance
104+
*
101105
* @return string
102106
*/
103107
public function activityTime()
@@ -107,7 +111,8 @@ public function activityTime()
107111

108112
/**
109113
* The feeds that should receive a copy of this instance when it's created
110-
* @return GetStream\Stream\Feed[]
114+
*
115+
* @return \GetStream\Stream\Feed[]
111116
*/
112117
public function activityNotify()
113118
{
@@ -116,7 +121,8 @@ public function activityNotify()
116121

117122
/**
118123
* The activity data for this instance
119-
* @return array[string]string
124+
*
125+
* @return array
120126
*/
121127
public function createActivity()
122128
{
@@ -147,5 +153,4 @@ public function createActivity()
147153

148154
return $activity;
149155
}
150-
151156
}
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
<?php namespace GetStream\StreamLaravel\Eloquent;
1+
<?php
22

3-
class CreateRemoveObserver {
3+
namespace GetStream\StreamLaravel\Eloquent;
44

5+
use Illuminate\Support\Facades\App;
6+
7+
class CreateRemoveObserver
8+
{
59
public function created($model)
610
{
7-
$manager = \App::make('feed_manager');
11+
$manager = App::make('feed_manager');
812
$manager->activityCreated($model);
913
}
1014

1115
public function deleting($model)
1216
{
13-
$manager = \App::make('feed_manager');
17+
$manager = App::make('feed_manager');
1418
$manager->activityDeleted($model);
1519
}
16-
1720
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
<?php namespace GetStream\StreamLaravel\Eloquent;
1+
<?php
22

3-
use GetStream\StreamLaravel\Exceptions\ModelReferenceException;
3+
namespace GetStream\StreamLaravel\Eloquent;
44

5-
class Utils {
5+
use GetStream\StreamLaravel\Exceptions\ModelReferenceException;
66

7+
class Utils
8+
{
79
public static function createModelReference($instance)
810
{
911
$className = get_class($instance);
1012
$pk = $instance->getKey();
13+
1114
if (empty($pk)) {
1215
throw new ModelReferenceException("Could not create a reference for instance of class $className", 1);
1316
}
17+
1418
return "$className:$pk";
1519
}
16-
1720
}

src/GetStream/StreamLaravel/Enrich.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
<?php namespace GetStream\StreamLaravel;
1+
<?php
22

3-
use GetStream\StreamLaravel\EnrichedActivity;
4-
use GetStream\StreamLaravel\Exceptions\MissingDataException;
3+
namespace GetStream\StreamLaravel;
54

6-
class Enrich {
5+
use Carbon\Carbon;
76

8-
private $fields = array();
7+
class Enrich
8+
{
9+
private $fields = [];
10+
private $withTrashed;
911

10-
public function __construct($fields = array('actor', 'object'), $withTrashed = true)
12+
public function __construct($fields = ['actor', 'object'], $withTrashed = true)
1113
{
1214
$this->fields = $fields;
1315
$this->withTrashed = $withTrashed;
1416
}
1517

16-
public function fromDb($model, $ids, $with=array())
18+
public function fromDb($model, $ids, $with = [])
1719
{
18-
$results = array();
20+
$results = [];
1921
$pkName = (new $model())->getKeyName();
2022
$query = $model::with($with)->whereIn($pkName, $ids);
2123
if (in_array('Illuminate\Database\Eloquent\SoftDeletingTrait', class_uses(get_class($model))) && $this->withTrashed) // previous withTrash method deprecated in Laravel 4.2
@@ -29,7 +31,7 @@ public function fromDb($model, $ids, $with=array())
2931

3032
private function collectReferences($activities)
3133
{
32-
$model_references = array();
34+
$model_references = [];
3335
foreach ($activities as $key => $activity) {
3436
foreach ($activity as $field=>$value) {
3537
if ($value === null) {
@@ -46,10 +48,10 @@ private function collectReferences($activities)
4648

4749
private function retrieveObjects($references)
4850
{
49-
$objects = array();
51+
$objects = [];
5052
foreach ($references as $content_type => $content_ids) {
5153
$content_type_model = new $content_type;
52-
$with = array();
54+
$with = [];
5355
if (method_exists($content_type_model, 'activityLazyLoading')) {
5456
$with = $content_type_model->activityLazyLoading();
5557
}
@@ -61,10 +63,11 @@ private function retrieveObjects($references)
6163

6264
private function wrapActivities($activities)
6365
{
64-
$wrappedActivities = array();
65-
foreach ($activities as $i => $activity) {
66+
$wrappedActivities = [];
67+
foreach ($activities as $activity) {
6668
$wrappedActivities[] = new EnrichedActivity($activity);
6769
}
70+
6871
return $wrappedActivities;
6972
}
7073

@@ -114,17 +117,16 @@ public function enrichAggregatedActivities($aggregatedActivities)
114117
return $aggregatedActivities;
115118
}
116119

117-
$references = array();
120+
$references = [];
118121
foreach ($aggregatedActivities as $aggregated) {
119122
$references = array_replace_recursive($references, $this->collectReferences($aggregated['activities']));
120123
}
121124

122125
$objects = $this->retrieveObjects($references);
123126
foreach ($aggregatedActivities as $key => $aggregated) {
124-
$aggregatedActivities[$key]['updated_at'] = new \Carbon\Carbon($aggregatedActivities[$key]['updated_at']);
127+
$aggregatedActivities[$key]['updated_at'] = new Carbon($aggregatedActivities[$key]['updated_at']);
125128
$this->injectObjects($aggregatedActivities[$key]['activities'], $objects);
126129
}
127130
return $aggregatedActivities;
128131
}
129-
130132
}

src/GetStream/StreamLaravel/EnrichedActivity.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
<?php namespace GetStream\StreamLaravel;
1+
<?php
22

3-
class EnrichedActivity implements \ArrayAccess, \IteratorAggregate {
4-
private $activityData = array();
5-
private $notEnrichedData = array();
3+
namespace GetStream\StreamLaravel;
4+
5+
use ArrayAccess;
6+
use ArrayIterator;
7+
use IteratorAggregate;
8+
9+
class EnrichedActivity implements ArrayAccess, IteratorAggregate
10+
{
11+
private $activityData = [];
12+
private $notEnrichedData = [];
613

714
public function __construct($activityData)
815
{
@@ -50,8 +57,8 @@ public function offsetGet($offset)
5057
}
5158

5259
// Support iteration over private activityData array
53-
public function getIterator() {
54-
return new \ArrayIterator($this->activityData);
60+
public function getIterator()
61+
{
62+
return new ArrayIterator($this->activityData);
5563
}
56-
5764
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<?php namespace GetStream\StreamLaravel\Exceptions;
1+
<?php
22

3-
class MissingDataException extends \Exception {
3+
namespace GetStream\StreamLaravel\Exceptions;
4+
5+
use Exception;
6+
7+
class MissingDataException extends Exception
8+
{
49
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<?php namespace GetStream\StreamLaravel\Exceptions;
1+
<?php
22

3-
class ModelReferenceException extends \Exception {
3+
namespace GetStream\StreamLaravel\Exceptions;
4+
5+
use Exception;
6+
7+
class ModelReferenceException extends Exception
8+
{
49
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
<?php namespace GetStream\StreamLaravel\Facades;
1+
<?php
22

3-
use Illuminate\Support\Facades\Facade;
3+
namespace GetStream\StreamLaravel\Facades;
44

5-
class FeedManager extends Facade {
5+
use Illuminate\Support\Facades\Facade;
66

7+
class FeedManager extends Facade
8+
{
79
/**
810
* Get the registered name of the component.
911
*
1012
* @return string
1113
*/
12-
protected static function getFacadeAccessor() { return 'feed_manager'; }
13-
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'feed_manager';
17+
}
1418
}

0 commit comments

Comments
 (0)