Skip to content

Commit 2433b31

Browse files
committed
:octocat: use chillerlan\Traits\{...}
1 parent 7f3ef4a commit 2433b31

File tree

7 files changed

+12
-350
lines changed

7 files changed

+12
-350
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"php": ">=7.0.3",
1919
"psr/simple-cache": "^1.0",
2020
"chillerlan/php-cache": "1.*",
21-
"chillerlan/php-traits": "1.0.*"
21+
"chillerlan/php-traits": "1.1.*"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "6.4.*"
24+
"phpunit/phpunit": "6.5.*"
2525
},
2626
"autoload": {
2727
"psr-4": {

src/Result.php

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212

1313
namespace chillerlan\Database;
1414

15-
use ArrayAccess, Countable, Iterator;
16-
use chillerlan\Database\Traits\{Enumerable, Magic};
15+
use ArrayAccess, Countable, SeekableIterator;
16+
use chillerlan\Traits\{
17+
Enumerable, Magic, Interfaces\ArrayAccessTrait, SPL\SeekableIteratorTrait, SPL\CountableTrait
18+
};
1719

1820
/**
1921
* @property int $length
2022
*
2123
* each($func [, $fieldname)
2224
*/
23-
class Result implements Iterator, ArrayAccess, Countable{
24-
use Enumerable, Magic;
25+
class Result implements SeekableIterator, ArrayAccess, Countable{
26+
use ArrayAccessTrait, SeekableIteratorTrait, CountableTrait, Magic, Enumerable;
2527

2628
/**
2729
* @var \chillerlan\Database\ResultRow[]
@@ -52,11 +54,11 @@ class Result implements Iterator, ArrayAccess, Countable{
5254
*
5355
* @throws \chillerlan\Database\ConnectionException
5456
*/
55-
public function __construct($data = null, $sourceEncoding = null, $destEncoding = 'UTF-8'){
57+
public function __construct($data = null, string $sourceEncoding = null, string $destEncoding = null){
5658
$this->sourceEncoding = $sourceEncoding;
57-
$this->destEncoding = $destEncoding;
59+
$this->destEncoding = $destEncoding ?? 'UTF-8';
5860

59-
if(is_null($data)){
61+
if($data === null){
6062
$data = [];
6163
}
6264
else if($data instanceof \Traversable){
@@ -130,24 +132,6 @@ protected function magic_get_length():int{
130132
* ArrayAccess *
131133
***************/
132134

133-
/**
134-
* @param int|string $offset
135-
*
136-
* @return bool
137-
*/
138-
public function offsetExists($offset):bool{
139-
return isset($this->array[$offset]);
140-
}
141-
142-
/**
143-
* @param int|string $offset
144-
*
145-
* @return \chillerlan\Database\ResultRow|mixed|null
146-
*/
147-
public function offsetGet($offset){
148-
return $this->array[$offset] ?? null;
149-
}
150-
151135
/**
152136
* @param int|string $offset
153137
* @param array $value
@@ -165,65 +149,4 @@ public function offsetSet($offset, $value){
165149

166150
}
167151

168-
/**
169-
* @param int|string $offset
170-
*
171-
* @return void
172-
*/
173-
public function offsetUnset($offset){
174-
unset($this->array[$offset]);
175-
}
176-
177-
178-
/*************
179-
* Countable *
180-
*************/
181-
182-
/**
183-
* @return int
184-
*/
185-
public function count():int{
186-
return count($this->array);
187-
}
188-
189-
190-
/************
191-
* Iterator *
192-
************/
193-
194-
/**
195-
* @return \chillerlan\Database\ResultRow|mixed
196-
*/
197-
public function current(){
198-
return $this->offsetGet($this->offset);
199-
}
200-
201-
/**
202-
* @return int
203-
*/
204-
public function key():int{
205-
return $this->offset;
206-
}
207-
208-
/**
209-
* @return bool
210-
*/
211-
public function valid():bool{
212-
return $this->offsetExists($this->offset);
213-
}
214-
215-
/**
216-
* @return void
217-
*/
218-
public function next(){
219-
$this->offset++;
220-
}
221-
222-
/**
223-
* @return void
224-
*/
225-
public function rewind(){
226-
$this->offset = 0;
227-
}
228-
229152
}

src/Traits/ClassLoader.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/Traits/Container.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/Traits/Enumerable.php

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)