Skip to content

Commit

Permalink
log_message function check added to adapt CI.
Browse files Browse the repository at this point in the history
.gitignore, LICENSE and README added.
  • Loading branch information
yahyaerturan committed Dec 2, 2019
1 parent ef1f03a commit d615a89
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
vendor
.idea
composer.lock
phpunit.xml
19 changes: 11 additions & 8 deletions Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,39 +264,42 @@ function str_snake_case_safe($title, $separator = '_')
*/
function str_json($str = '/', $returnDecoded = true, $asArray = false)
{
if ((str_starts('{', $str) == true) and (str_ends('}', $str) == true)) {
$ciEnv = function_exists('log_message') ? true : false;

if ((str_starts('{', $str) == true) && (str_ends('}', $str) == true)) {
$json = json_decode($str, $asArray);

switch (json_last_error()) {
case JSON_ERROR_NONE:
return ($returnDecoded) ? $json : true;
break;
case JSON_ERROR_DEPTH:
log_message('debug', 'str_json: Maximum stack depth exceeded.');
!$ciEnv || log_message('debug', 'str_json: Maximum stack depth exceeded.');
return false;
break;
case JSON_ERROR_STATE_MISMATCH:
log_message('debug', 'str_json: Underflow or the modes mismatch.');
!$ciEnv || log_message('debug', 'str_json: Underflow or the modes mismatch.');
return false;
break;
case JSON_ERROR_CTRL_CHAR:
log_message('debug', 'str_json: Unexpected control character found.');
!$ciEnv || log_message('debug', 'str_json: Unexpected control character found.');
return false;
break;
case JSON_ERROR_SYNTAX:
log_message('debug', 'str_json: Syntax error, malformed JSON.');
!$ciEnv || log_message('debug', 'str_json: Syntax error, malformed JSON.');
return false;
break;
case JSON_ERROR_UTF8:
log_message('debug', 'str_json: Malformed UTF-8 characters, possibly incorrectly encoded.');
!$ciEnv || log_message('debug', 'str_json: Malformed UTF-8 characters, possibly incorrectly encoded.');
return false;
break;
default:
log_message('debug', 'str_json: Unknown error.');
!$ciEnv || log_message('debug', 'str_json: Unknown error.');
return false;
break;
}
} else {
log_message('debug', 'str_json: String does not starts or ends properly.');
!$ciEnv || log_message('debug', 'str_json: String does not starts or ends properly.');
return false;
}
}
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2019-2023 Yahya Erturan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Str - Str Utilities for PHP

- str_starts($needles, $haystack)
- str_contains($needles, $haystack)
- str_ends($needles, $haystack)
- str_limit($value, $limit = 100, $end = '...') {
- str_snake_case($value, $delimiter = '\_')
- str_camel_case($value)
- str_studly_case($value)
- str_slug($title, $separator = '-')
- str_snake_case_safe($title, $separator = '_')
- str_json($str = '/', $returnDecoded = true, $asArray = false)

## Install

Install the latest version using [Composer](https://getcomposer.org/):

```
$ composer require vayes/str
```

Not available via composer yet.

## Usage

Import and use as it is:

```php
use function Vayes\Str\str_camel_case

$property = str_camel_case('snaked_case_string');
```

## License

[MIT license](LICENSE.md)

0 comments on commit d615a89

Please sign in to comment.