Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit d3f672c

Browse files
committed
some update
1 parent 586c544 commit d3f672c

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

src/Collections/LiteCollection.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ public function replace(array $items)
8080
}
8181
}
8282

83+
/**
84+
* @param callable $filter
85+
* @return static
86+
*/
87+
public function reject(callable $filter)
88+
{
89+
$data = [];
90+
91+
foreach ($this as $key => $value) {
92+
if (!$filter($value, $key)) {
93+
$data[$key] = $value;
94+
}
95+
96+
unset($this[$key]);
97+
}
98+
99+
return new static($data);
100+
}
101+
83102
/**
84103
* @param callable $callback
85104
* @return static
@@ -90,6 +109,7 @@ public function map(callable $callback)
90109

91110
foreach ($this as $key => $value) {
92111
$data[$key] = $callback($value, $key);
112+
unset($this[$key]);
93113
}
94114

95115
return new static($data);
@@ -101,14 +121,14 @@ public function map(callable $callback)
101121
*/
102122
public function implode($char = ',')
103123
{
104-
$string = '';
105-
106-
foreach ($this as $key => $value) {
124+
// $string = '';
125+
//
126+
// foreach ($this as $key => $value) {
107127
// $string .= is_array($value) ? $this->implode($char, $value) : implode($char, $value);
108-
$string .= implode($char, $value);
109-
}
128+
// $string .= implode($char, $value);
129+
// }
110130

111-
return $string;
131+
return implode($char, $this->all());
112132
}
113133

114134
/**

src/Collections/SimpleCollection.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ public function sets(array $data)
123123
return $this;
124124
}
125125

126+
/**
127+
* @param callable $filter
128+
* @return static
129+
*/
130+
public function reject(callable $filter)
131+
{
132+
$data = [];
133+
134+
foreach ($this as $key => $value) {
135+
if (!$filter($value, $key)) {
136+
$data[$key] = $value;
137+
}
138+
139+
unset($this[$key]);
140+
}
141+
142+
return new static($data);
143+
}
144+
126145
/**
127146
* @param callable $callback
128147
* @return static
@@ -133,6 +152,7 @@ public function map(callable $callback)
133152

134153
foreach ($this->getIterator() as $key => $value) {
135154
$data[$key] = $callback($value, $key);
155+
unset($this[$key]);
136156
}
137157

138158
return new static($data);
@@ -144,14 +164,7 @@ public function map(callable $callback)
144164
*/
145165
public function implode($char = ',')
146166
{
147-
$string = '';
148-
149-
foreach ($this->getIterator() as $key => $value) {
150-
// $string .= is_array($value) ? $this->implode($char, $value) : implode($char, $value);
151-
$string .= implode($char, $value);
152-
}
153-
154-
return $string;
167+
return implode($char, $this->all());
155168
}
156169

157170
/**

src/Helpers/Str.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@ public static function optional(string $string, string $prefix = ' ', string $su
3131
}
3232

3333
/**
34-
* @param string $needle
35-
* @param string|array $string
34+
* @param string $string
35+
* @param string|array $needle
3636
* @return bool
3737
*/
38-
public static function contains(string $needle, $string)
38+
public static function contains(string $string, $needle)
3939
{
40-
return self::has($needle, $string);
40+
return self::has($string, $needle);
4141
}
4242

4343
/**
44-
* @param string $needle
45-
* @param string|array $string
44+
* @param string $string
45+
* @param string|array $needle
4646
* @return bool
4747
*/
48-
public static function has(string $needle, $string)
48+
public static function has(string $string, $needle)
4949
{
5050
if (is_string($string)) {
5151
return stripos($string, $needle) !== false;
5252
}
5353

54-
if (is_array($string)) {
55-
foreach ((array)$string as $item) {
56-
if (stripos($item, $needle) !== false) {
54+
if (is_array($needle)) {
55+
foreach ((array)$needle as $item) {
56+
if (stripos($string, $item) !== false) {
5757
return true;
5858
}
5959
}

0 commit comments

Comments
 (0)