@@ -17,20 +17,20 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @since 2.1.0 |
19 | 19 | */ |
20 | - public function __construct( $slug ) { |
|
20 | + public function __construct($slug) { |
|
21 | 21 | |
22 | - parent::__construct( $slug ); |
|
22 | + parent::__construct($slug); |
|
23 | 23 | |
24 | - $parts = wordpoints_parse_dynamic_slug( $this->slug ); |
|
24 | + $parts = wordpoints_parse_dynamic_slug($this->slug); |
|
25 | 25 | |
26 | - if ( $parts['dynamic'] ) { |
|
26 | + if ($parts['dynamic']) { |
|
27 | 27 | |
28 | - $parsed = $this->parse_slug( $this->related_entity_slug ); |
|
28 | + $parsed = $this->parse_slug($this->related_entity_slug); |
|
29 | 29 | |
30 | 30 | $this->primary_entity_slug = "{$this->primary_entity_slug}\\{$parts['dynamic']}"; |
31 | 31 | $this->related_entity_slug = "{$parsed['slug']}\\{$parts['dynamic']}"; |
32 | 32 | |
33 | - if ( $parsed['is_array'] ) { |
|
33 | + if ($parsed['is_array']) { |
|
34 | 34 | $this->related_entity_slug .= '{}'; |
35 | 35 | } |
36 | 36 | } |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function get_title() { |
43 | 43 | |
44 | - $parsed = $this->parse_slug( $this->related_entity_slug ); |
|
44 | + $parsed = $this->parse_slug($this->related_entity_slug); |
|
45 | 45 | |
46 | - $entity = wordpoints_entities()->get( $parsed['slug'] ); |
|
46 | + $entity = wordpoints_entities()->get($parsed['slug']); |
|
47 | 47 | |
48 | - if ( $entity instanceof WordPoints_Entity ) { |
|
48 | + if ($entity instanceof WordPoints_Entity) { |
|
49 | 49 | return $entity->get_title(); |
50 | 50 | } else { |
51 | 51 | return $this->related_entity_slug; |
@@ -37,8 +37,8 @@ |
||
37 | 37 | /** |
38 | 38 | * @since 2.1.0 |
39 | 39 | */ |
40 | - protected function get_related_entity_ids( WordPoints_Entity $entity ) { |
|
41 | - return $entity->get_the_attr_value( $this->related_ids_field ); |
|
40 | + protected function get_related_entity_ids(WordPoints_Entity $entity) { |
|
41 | + return $entity->get_the_attr_value($this->related_ids_field); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @return mixed The attribute value. |
41 | 41 | */ |
42 | - abstract protected function get_attr_value_from_entity( WordPoints_Entity $entity ); |
|
42 | + abstract protected function get_attr_value_from_entity(WordPoints_Entity $entity); |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Get the data type of this attribute's values. |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return bool Whether the value was set correctly. |
68 | 68 | */ |
69 | - public function set_the_value_from_entity( WordPoints_Entity $entity ) { |
|
69 | + public function set_the_value_from_entity(WordPoints_Entity $entity) { |
|
70 | 70 | |
71 | - $this->the_value = $this->get_attr_value_from_entity( $entity ); |
|
71 | + $this->the_value = $this->get_attr_value_from_entity($entity); |
|
72 | 72 | |
73 | 73 | return true; |
74 | 74 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | * |
24 | 24 | * @return bool Whether the value was set successfully. |
25 | 25 | */ |
26 | - public function set_the_value_from_entity( WordPoints_Entity $entity ); |
|
26 | + public function set_the_value_from_entity(WordPoints_Entity $entity); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // EOF |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @param WordPoints_Entity|null $entity An entity. |
50 | 50 | */ |
51 | - public function __construct( WordPoints_Entity $entity = null ) { |
|
52 | - if ( isset( $entity ) ) { |
|
53 | - $this->add_entity( $entity ); |
|
51 | + public function __construct(WordPoints_Entity $entity = null) { |
|
52 | + if (isset($entity)) { |
|
53 | + $this->add_entity($entity); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -64,20 +64,20 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * @since 2.1.0 |
66 | 66 | */ |
67 | - public function add_entity( WordPoints_Entity $entity ) { |
|
67 | + public function add_entity(WordPoints_Entity $entity) { |
|
68 | 68 | |
69 | - $this->entities[ $entity->get_slug() ] = $entity; |
|
69 | + $this->entities[$entity->get_slug()] = $entity; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @since 2.1.0 |
74 | 74 | */ |
75 | - public function remove_entity( $slug ) { |
|
75 | + public function remove_entity($slug) { |
|
76 | 76 | |
77 | - unset( $this->entities[ $slug ] ); |
|
77 | + unset($this->entities[$slug]); |
|
78 | 78 | |
79 | 79 | if ( |
80 | - isset( $this->hierarchy[0] ) |
|
80 | + isset($this->hierarchy[0]) |
|
81 | 81 | && $this->hierarchy[0]->get_slug() === $slug |
82 | 82 | ) { |
83 | 83 | $this->current = null; |
@@ -88,30 +88,30 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * @since 2.1.0 |
90 | 90 | */ |
91 | - public function descend( $child_slug ) { |
|
91 | + public function descend($child_slug) { |
|
92 | 92 | |
93 | - if ( ! $this->current ) { |
|
93 | + if ( ! $this->current) { |
|
94 | 94 | |
95 | - if ( ! isset( $this->entities[ $child_slug ] ) ) { |
|
95 | + if ( ! isset($this->entities[$child_slug])) { |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | - $child = $this->entities[ $child_slug ]; |
|
99 | + $child = $this->entities[$child_slug]; |
|
100 | 100 | |
101 | 101 | } else { |
102 | 102 | |
103 | - if ( ! ( $this->current instanceof WordPoints_Entity_ParentI ) ) { |
|
103 | + if ( ! ($this->current instanceof WordPoints_Entity_ParentI)) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
107 | - $child = $this->current->get_child( $child_slug ); |
|
107 | + $child = $this->current->get_child($child_slug); |
|
108 | 108 | |
109 | - if ( ! $child ) { |
|
109 | + if ( ! $child) { |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - if ( $this->current ) { |
|
114 | + if ($this->current) { |
|
115 | 115 | $this->hierarchy[] = $this->current; |
116 | 116 | } |
117 | 117 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function ascend() { |
127 | 127 | |
128 | - if ( empty( $this->current ) ) { |
|
128 | + if (empty($this->current)) { |
|
129 | 129 | |
130 | 130 | // We're already at the top, some logic is probably wrong. |
131 | 131 | _doing_it_wrong( |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | |
140 | - $this->current = array_pop( $this->hierarchy ); |
|
140 | + $this->current = array_pop($this->hierarchy); |
|
141 | 141 | |
142 | 142 | return true; |
143 | 143 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | /** |
153 | 153 | * @since 2.1.0 |
154 | 154 | */ |
155 | - public function get_from_hierarchy( array $hierarchy ) { |
|
155 | + public function get_from_hierarchy(array $hierarchy) { |
|
156 | 156 | |
157 | 157 | $backup = $this->hierarchy; |
158 | 158 | $current = $this->current; |
@@ -160,16 +160,16 @@ discard block |
||
160 | 160 | $this->hierarchy = array(); |
161 | 161 | $this->current = null; |
162 | 162 | |
163 | - $slug = reset( $hierarchy ); |
|
163 | + $slug = reset($hierarchy); |
|
164 | 164 | |
165 | - while ( $slug ) { |
|
165 | + while ($slug) { |
|
166 | 166 | |
167 | - if ( ! $this->descend( $slug ) ) { |
|
167 | + if ( ! $this->descend($slug)) { |
|
168 | 168 | $this->current = null; |
169 | 169 | break; |
170 | 170 | } |
171 | 171 | |
172 | - $slug = next( $hierarchy ); |
|
172 | + $slug = next($hierarchy); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $entityish = $this->current; |
@@ -42,61 +42,61 @@ discard block |
||
42 | 42 | * the restrictions of this type for this |
43 | 43 | * entity. |
44 | 44 | */ |
45 | - public function get( $entity_id, $hierarchy, $type = 'know' ) { |
|
45 | + public function get($entity_id, $hierarchy, $type = 'know') { |
|
46 | 46 | |
47 | 47 | $hierarchy = (array) $hierarchy; |
48 | 48 | $restrictions = array(); |
49 | - $class_hierarchies = array( $hierarchy ); |
|
49 | + $class_hierarchies = array($hierarchy); |
|
50 | 50 | |
51 | - $depth = count( $hierarchy ); |
|
51 | + $depth = count($hierarchy); |
|
52 | 52 | |
53 | - if ( 1 === $depth ) { |
|
53 | + if (1 === $depth) { |
|
54 | 54 | $class_hierarchies[] = array(); |
55 | 55 | } |
56 | 56 | |
57 | - if ( is_array( $entity_id ) ) { |
|
57 | + if (is_array($entity_id)) { |
|
58 | 58 | |
59 | 59 | $context = $entity_id; |
60 | - $entity_slug = $hierarchy[ $depth - ( $depth % 2 ? 1 : 2 ) ]; |
|
61 | - $entity_id = $context[ $entity_slug ]; |
|
60 | + $entity_slug = $hierarchy[$depth - ($depth % 2 ? 1 : 2)]; |
|
61 | + $entity_id = $context[$entity_slug]; |
|
62 | 62 | |
63 | - unset( $context[ $entity_slug ] ); |
|
63 | + unset($context[$entity_slug]); |
|
64 | 64 | |
65 | 65 | /** @var WordPoints_Entity_Contexts $contexts */ |
66 | - $contexts = wordpoints_entities()->get_sub_app( 'contexts' ); |
|
67 | - $contexts->switch_to( $context ); |
|
66 | + $contexts = wordpoints_entities()->get_sub_app('contexts'); |
|
67 | + $contexts->switch_to($context); |
|
68 | 68 | } |
69 | 69 | |
70 | - $types = array( $type ); |
|
70 | + $types = array($type); |
|
71 | 71 | |
72 | 72 | // If a user isn't allowed to even know about an entity, they can't do |
73 | 73 | // anything else either. So we always check that too. |
74 | - if ( 'know' !== $type ) { |
|
74 | + if ('know' !== $type) { |
|
75 | 75 | $types[] = 'know'; |
76 | 76 | } |
77 | 77 | |
78 | - foreach ( $types as $type ) { |
|
78 | + foreach ($types as $type) { |
|
79 | 79 | |
80 | - $sub_app = $this->get_sub_app( $type ); |
|
80 | + $sub_app = $this->get_sub_app($type); |
|
81 | 81 | |
82 | - if ( ! $sub_app instanceof WordPoints_Class_Registry_Deep_Multilevel ) { |
|
82 | + if ( ! $sub_app instanceof WordPoints_Class_Registry_Deep_Multilevel) { |
|
83 | 83 | continue; |
84 | 84 | } |
85 | 85 | |
86 | - foreach ( $class_hierarchies as $class_hierarchy ) { |
|
86 | + foreach ($class_hierarchies as $class_hierarchy) { |
|
87 | 87 | |
88 | 88 | $type_restrictions = $sub_app->get_children( |
89 | 89 | $class_hierarchy |
90 | - , array( $entity_id, $hierarchy ) |
|
90 | + , array($entity_id, $hierarchy) |
|
91 | 91 | ); |
92 | 92 | |
93 | - if ( ! $type_restrictions ) { |
|
93 | + if ( ! $type_restrictions) { |
|
94 | 94 | continue; |
95 | 95 | } |
96 | 96 | |
97 | 97 | $restrictions = array_merge( |
98 | 98 | $restrictions |
99 | - , array_values( $type_restrictions ) |
|
99 | + , array_values($type_restrictions) |
|
100 | 100 | ); |
101 | 101 | } |
102 | 102 | } |
@@ -105,10 +105,10 @@ discard block |
||
105 | 105 | $entity_id |
106 | 106 | , $hierarchy |
107 | 107 | , $restrictions |
108 | - , isset( $context ) ? $context : array() |
|
108 | + , isset($context) ? $context : array() |
|
109 | 109 | ); |
110 | 110 | |
111 | - if ( isset( $contexts ) ) { |
|
111 | + if (isset($contexts)) { |
|
112 | 112 | $contexts->switch_back(); |
113 | 113 | } |
114 | 114 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @param string $slug The slug of this context. |
57 | 57 | */ |
58 | - public function __construct( $slug ) { |
|
58 | + public function __construct($slug) { |
|
59 | 59 | $this->slug = $slug; |
60 | 60 | } |
61 | 61 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return bool Whether the context was switched to successfully. |
100 | 100 | */ |
101 | - public function switch_to( $id ) { |
|
101 | + public function switch_to($id) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | 104 |
@@ -29,22 +29,22 @@ |
||
29 | 29 | /** |
30 | 30 | * @since 2.1.0 |
31 | 31 | */ |
32 | - protected function get_entity_human_id( $entity ) { |
|
32 | + protected function get_entity_human_id($entity) { |
|
33 | 33 | |
34 | 34 | $names = wp_roles()->get_names(); |
35 | 35 | |
36 | - if ( ! isset( $names[ $entity->name ] ) ) { |
|
36 | + if ( ! isset($names[$entity->name])) { |
|
37 | 37 | return false; |
38 | 38 | } |
39 | 39 | |
40 | - return translate_user_role( $names[ $entity->name ] ); |
|
40 | + return translate_user_role($names[$entity->name]); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @since 2.1.0 |
45 | 45 | */ |
46 | 46 | public function get_title() { |
47 | - return __( 'Role', 'wordpoints' ); |
|
47 | + return __('Role', 'wordpoints'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -34,15 +34,15 @@ |
||
34 | 34 | /** |
35 | 35 | * @since 2.1.0 |
36 | 36 | */ |
37 | - protected function get_related_entity_ids( WordPoints_Entity $entity ) { |
|
38 | - return $entity->get_the_attr_value( $this->related_ids_field ); |
|
37 | + protected function get_related_entity_ids(WordPoints_Entity $entity) { |
|
38 | + return $entity->get_the_attr_value($this->related_ids_field); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @since 2.1.0 |
43 | 43 | */ |
44 | 44 | public function get_title() { |
45 | - return __( 'Roles', 'wordpoints' ); |
|
45 | + return __('Roles', 'wordpoints'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |