Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit afcdf32

Browse files
Merge branch 'release/1.0.0'
2 parents ff9cc70 + a2284d5 commit afcdf32

File tree

7 files changed

+84
-37
lines changed

7 files changed

+84
-37
lines changed

CHANGELOG.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
66

77
## Unreleased
88

9+
## 1.0.0 (2018-07-22)
10+
911
### Added
1012

11-
-
13+
- rand_bool helper
14+
- str_wrap helper
15+
_ is\_assoc\_array helper
16+
- array_expand helper
17+
- array_without helper
18+
- array\_pull\_value helper
19+
- array\_pull\_values helper
20+
- array_hash helper
21+
- object_hash helper
22+
- has\_public\_method helper
23+
- carbon helper
24+
- create\_temporary\_file helper
25+
- sss helper
26+
- ddd helper
27+
- sss_if helper
28+
- ddd_if helper
29+
- Constants trait
30+
- ProvidesClassInfo trait
31+
- MethodHelper class

README.md

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
<p align="center">
1+
# An extensive set of PHP helper functions and classes
2+
23
<a href="https://packagist.org/packages/sebastiaanluca/php-helpers"><img src="https://poser.pugx.org/sebastiaanluca/php-helpers/version" alt="Latest stable release"></img></a>
34
<a href="LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="Software license"></img></a>
45
<a href="https://travis-ci.org/sebastiaanluca/php-helpers"><img src="https://img.shields.io/travis/sebastiaanluca/php-helpers/master.svg" alt="Build status"></img></a>
56
<a href="https://packagist.org/packages/sebastiaanluca/php-helpers"><img src="https://img.shields.io/packagist/dt/sebastiaanluca/php-helpers.svg" alt="Total downloads"></img></a>
6-
</p>
77

8-
<p align="center">
98
<a href="https://blog.sebastiaanluca.com"><img src="https://img.shields.io/badge/link-blog-lightgrey.svg" alt="Read my blog"></img></a>
109
<a href="https://packagist.org/packages/sebastiaanluca"><img src="https://img.shields.io/badge/link-other_packages-lightgrey.svg" alt="View my other packages and projects"></img></a>
1110
<a href="https://twitter.com/sebastiaanluca"><img src="https://img.shields.io/twitter/follow/sebastiaanluca.svg?style=social" alt="Follow @sebastiaanluca on Twitter"></img></a>
1211
<a href="https://twitter.com/intent/tweet?text=Check%20out%20this%20extensive%20set%20of%20generic%20PHP%20helper%20functions%20and%20classes!%20Via%20@sebastiaanluca%20https://github.com/sebastiaanluca/php-helpers"><img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=social" alt="Share this package on Twitter"></img></a>
13-
</p>
14-
15-
# PHP Helpers
16-
17-
**An extensive set of PHP helper functions and classes.**
1812

1913
## Table of contents
2014

@@ -32,7 +26,7 @@
3226
- [object_hash](#object_hash)
3327
- [has\_public\_method](#has_public_method)
3428
- [carbon](#carbon)
35-
- [create\_temporary\_file](#create_temporary_file)
29+
- [temporary_file](#temporary_file)
3630
- [Debug global helper functions](#debug-global-helper-functions)
3731
- [sss](#sss)
3832
- [ddd](#ddd)
@@ -273,7 +267,7 @@ Carbon\Carbon {
273267
*/
274268
```
275269

276-
### create\_temporary\_file
270+
### temporary_file
277271

278272
Create a temporary file.
279273

@@ -284,7 +278,7 @@ The temporary file is readable and writeable by default. The file is automatical
284278
See [](http://php.net/manual/en/function.tmpfile.php) for more information.
285279

286280
```php
287-
create_temporary_file();
281+
temporary_file();
288282

289283
/*
290284
[
@@ -576,7 +570,6 @@ If you discover any security related issues, please email [hello@sebastiaanluca.
576570
## Credits
577571

578572
- [Sebastiaan Luca][link-github-profile]
579-
- Logo by [Vitor Caneco](https://github.com/caneco)
580573
- [All Contributors][link-contributors]
581574

582575
## About

src/Classes/Constants.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function constants() : array
2323
*/
2424
public static function keys() : array
2525
{
26-
return array_keys(static::all());
26+
return array_keys(static::constants());
2727
}
2828

2929
/**
@@ -33,6 +33,6 @@ public static function keys() : array
3333
*/
3434
public static function values() : array
3535
{
36-
return array_values(static::all());
36+
return array_values(static::constants());
3737
}
3838
}

src/Classes/MethodHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public static function hasMethodOfType($object, $method, $type) : bool
2525

2626
try {
2727
$reflection = new ReflectionMethod($object, $method);
28-
// FIXME
29-
$type = 'is' . studly_case($type);
28+
29+
$type = 'is' . ucfirst($type);
3030

3131
return $reflection->{$type}();
3232
} catch (ReflectionException $exception) {

src/Functions/generic.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Carbon\Carbon;
44
use SebastiaanLuca\PhpHelpers\Classes\MethodHelper;
5+
use SebastiaanLuca\PhpHelpers\InternalHelpers;
56

67
if (! function_exists('rand_bool')) {
78
/**
@@ -64,8 +65,7 @@ function array_expand(array $array) : array
6465
$expanded = [];
6566

6667
foreach ($array as $key => $value) {
67-
// FIXME
68-
array_set($expanded, $key, $value);
68+
InternalHelpers::arraySet($expanded, $key, $value);
6969
}
7070

7171
return $expanded;
@@ -83,8 +83,9 @@ function array_expand(array $array) : array
8383
*/
8484
function array_without(array $array, $values) : array
8585
{
86-
// FIXME
87-
return array_values(array_diff($array, array_wrap($values)));
86+
$values = ! is_array($values) ? [$values] : $values;
87+
88+
return array_values(array_diff($array, $values));
8889
}
8990
}
9091

@@ -185,7 +186,7 @@ function carbon($timeString = null) : Carbon
185186
}
186187
}
187188

188-
if (! function_exists('create_temporary_file')) {
189+
if (! function_exists('temporary_file')) {
189190
/**
190191
* Create a temporary file.
191192
*
@@ -197,7 +198,7 @@ function carbon($timeString = null) : Carbon
197198
*
198199
* @return array An array with a `file` and `path` key.
199200
*/
200-
function create_temporary_file() : array
201+
function temporary_file() : array
201202
{
202203
$file = tmpfile();
203204
$path = stream_get_meta_data($file)['uri'];

src/InternalHelpers.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SebastiaanLuca\PhpHelpers;
6+
7+
class InternalHelpers
8+
{
9+
/**
10+
* Set an array item to a given value using "dot" notation.
11+
*
12+
* If no key is given to the method, the entire array will be replaced.
13+
*
14+
* @param array $array
15+
* @param string $key
16+
* @param mixed $value
17+
*
18+
* @return array
19+
*/
20+
public static function arraySet(array &$array, string $key, $value) : array
21+
{
22+
$keys = explode('.', $key);
23+
24+
while (count($keys) > 1) {
25+
$key = array_shift($keys);
26+
27+
// If the key doesn't exist at this depth, we will just create an empty array
28+
// to hold the next value, allowing us to create the arrays to hold final
29+
// values at the correct depth. Then we'll keep digging into the array.
30+
if (! isset($array[$key]) || ! is_array($array[$key])) {
31+
$array[$key] = [];
32+
}
33+
34+
$array = &$array[$key];
35+
}
36+
37+
$array[array_shift($keys)] = $value;
38+
39+
return $array;
40+
}
41+
}

tests/Unit/Functions/GenericHelpersTest.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,9 @@ public function object_hash generate an object hash() : void
118118
/**
119119
* @test
120120
*/
121-
public function carbonize creates a carbon instance from a string() : void
121+
public function carbon creates a carbon instance from a string() : void
122122
{
123-
$this->assertEquals(new Carbon('tomorrow'), carbonize('tomorrow'));
124-
}
125-
126-
/**
127-
* @test
128-
*/
129-
public function take creates a pipe item() : void
130-
{
131-
$this->assertInstanceOf(Item::class, take('value'));
123+
$this->assertEquals(new Carbon('tomorrow'), carbon('tomorrow'));
132124
}
133125

134126
/**
@@ -154,9 +146,9 @@ public function myMethod()
154146
/**
155147
* @test
156148
*/
157-
public function create_temporary_file creates a temporary file and returns its pointer and full path() : void
149+
public function temporary_file creates a temporary file and returns its pointer and full path() : void
158150
{
159-
$file = create_temporary_file();
151+
$file = temporary_file();
160152

161153
$this->assertArrayHasKey('file', $file);
162154
$this->assertArrayHasKey('path', $file);
@@ -170,9 +162,9 @@ public function create_temporary_file creates a temporary file and returns
170162
/**
171163
* @test
172164
*/
173-
public function the file created by create_temporary_file is automatically deleted when it goes out of scope() : void
165+
public function the file created by temporary_file is automatically deleted when it goes out of scope() : void
174166
{
175-
$file = create_temporary_file();
167+
$file = temporary_file();
176168

177169
$path = $file['path'];
178170

0 commit comments

Comments
 (0)