Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Update for PHP8
Browse files Browse the repository at this point in the history
  • Loading branch information
repat committed Dec 8, 2020
1 parent 97d9945 commit 4bac2a7
Show file tree
Hide file tree
Showing 6 changed files with 1,472 additions and 560 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
vendor/
.idea/
.phpunit.result.cache
32 changes: 15 additions & 17 deletions README.md
Expand Up @@ -13,14 +13,15 @@ composer require calebporzio/awesome-helpers
**carbon**

Shortcut for: `new Carbon` or `Carbon::parse()`

``` php
carbon('One year ago');
```


**chain**

Makes an ordinary object chainable.

```php
chain(new SomeClass)
->firstMethod()
Expand All @@ -34,7 +35,6 @@ chain(new Str)->singular('cars')->ucfirst(carry)();
// a "()" on the end of it. (Thanks to Taylor Otwell for these two additions)
```


**connection**

Run callback under a different database connection.
Expand All @@ -45,33 +45,32 @@ $tenantPostIds = connection('tenantdb', function () {
});
```


**dump_sql**

Returns sql query with bindings data.

```php
dump_sql(\DB::table('users')->where('email', "blaBla")->where('id', 1));
dump_sql(\DB::table('users')->where('email', "blaBla")->where('id', 1));
// returns "select * from `users` where `email` = 'blaBla' and `id` = 1"
```


**faker**

Shortcut for: `$faker = Faker\Factory::create()`

``` php
faker()->address; // returns random, fake address
faker('address'); // alternate syntax
```


**user**

A shortcut for `auth()->user()`

```php
user()->posts()->create([...]);
```


**money**

```php
Expand All @@ -82,27 +81,28 @@ echo money(12.75, true, 'en_GB'); // echos "£12.75"
// Note: unless specified otherwise, money() will detect the current locale.
```


**ok**

Shortcut for `response('', 204)`. When you don't have anything to return from an endpoint, but you want to return success.

```php
return ok();
```


**stopwatch**

Returns the amount of time (in seconds) the provided callback took to execute. Useful for debugging and profiling.

```php
stopwatch(function () {
sleep(2);
}); // returns "2.0"
```


**str_between**

Returns string between second argument

```php
str_between('--thing--', '--'); // returns "thing"
str_between('[thing]', '[', ']'); // returns "thing"
Expand All @@ -111,22 +111,21 @@ Str::between('--thing--', '--'); // returns "thing"
Str::between('[thing]', '[', ']'); // returns "thing"
```


**str_extract**

Returns capture groups contained in the provided regex pattern.
```php

```php
str_extract('Jan-01-2019', '/Jan-(.*)-2019/'); // returns "01"

Str::extract('Jan-01-2019', '/Jan-(.*)-2019/'); // returns "01"

```


**str_match**

Checks the provided string against the provided regex pattern.

```php

str_match('Jan-01-2019', '/Jan-.*-2019/'); // returns true
Expand All @@ -136,10 +135,10 @@ Str::match('Jan-1-2019', '/Jan-(.*)-2019/'); // returns true

```


**str_validate**

A simple way to use validate a string using Laravel's built-in validation system.

```php
str_validate('calebporzio@aol.com', 'regex:/\.net$/|email|max:10');
// returns: ["Format is invalid.", "May not be greater than 10 characters."]
Expand All @@ -148,7 +147,6 @@ Str::validate('calebporzio@aol.com', 'regex:/\.net$/|email|max:10');
// returns: ["Format is invalid.", "May not be greater than 10 characters."]
```


**str_wrap**

```php
Expand All @@ -157,7 +155,6 @@ str_wrap('thing', '--'); // returns "--thing--"
Str::wrap('thing', '--'); // returns "--thing--"
```


**swap**

This function swaps the values of two variables.
Expand All @@ -174,16 +171,17 @@ echo $startDate; // prints "2020-01-01"
echo $endDate; // prints "2040-01-01"
```


**tinker**

Kind of like `dd()`, but will open an `artisan tinker` terminal session with the variables you passed in, so you can play around.

```php
$somethingYouWantToDebug = new StdClass;
tinker($somethingYouWantToDebug);
```

## Am I missing an awesome helper function?

Submit a PR or issue with helper functions you use or ideas you have for others!

TTFN,
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -14,13 +14,13 @@
}
],
"require": {
"php": "^7.1"
"php": ">=7.1"
},
"require-dev": {
"fzaninotto/faker": "^1.8",
"fakerphp/faker": "^1.12",
"illuminate/support": "5.7.*|5.8.*|^6.0.0|^7.0.0",
"mockery/mockery": "dev-master",
"phpunit/phpunit": "^7.0|^8.0"
"phpunit/phpunit": "^8.0|^9.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 4bac2a7

Please sign in to comment.