Skip to content

Commit 442beea

Browse files
committed
refactor: update comments
Update comments; website, urls...
1 parent 38e6e4a commit 442beea

File tree

5 files changed

+75
-68
lines changed

5 files changed

+75
-68
lines changed

src/Exception/JsonException.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<?php
2+
23
/**
3-
* PHP simple library for managing Json files.
4+
* PHP simple library for managing JSON files.
45
*
5-
* @author Josantonius <hello@josantonius.com>
6-
* @copyright 2016 - 2018 (c) Josantonius - PHP-Json
6+
* @author Josantonius <hello@josantonius.dev>
7+
* @copyright 2016 (c) Josantonius
78
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
8-
* @link https://github.com/Josantonius/PHP-Json
9+
* @link https://github.com/josantonius/php-json
910
* @since 1.0.0
1011
*/
1112
namespace Josantonius\Json\Exception;
1213

1314
/**
14-
* Exception class for Json library.
15+
* Exception class for JSON library.
1516
*
1617
* You can use an exception and error handler with this library.
1718
*
18-
* @link https://github.com/Josantonius/PHP-ErrorHandler
19+
* @link https://github.com/josantonius/php-errorhandler
1920
*/
2021
class JsonException extends \Exception
2122
{
@@ -27,7 +28,7 @@ class JsonException extends \Exception
2728
*/
2829
public function __construct($msg = '', $status = 0)
2930
{
30-
$this->message = $msg;
31+
$this->message = $msg;
3132
$this->statusCode = $status;
3233
}
3334
}

src/Json.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
2+
23
/**
3-
* PHP simple library for managing Json files.
4+
* PHP simple library for managing JSON files.
45
*
5-
* @author Josantonius <hello@josantonius.com>
6-
* @copyright 2016 - 2018 (c) Josantonius - PHP-Json
6+
* @author Josantonius <hello@josantonius.dev>
7+
* @copyright 2016 (c) Josantonius
78
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
8-
* @link https://github.com/Josantonius/PHP-Json
9+
* @link https://github.com/josantonius/php-json
910
* @since 1.0.0
1011
*/
12+
1113
namespace Josantonius\Json;
1214

1315
use Josantonius\Json\Exception\JsonException;
@@ -47,12 +49,12 @@ public static function arrayToFile($array, $file)
4749
*/
4850
public static function fileToArray($file)
4951
{
50-
if (! is_file($file) && ! filter_var($file, FILTER_VALIDATE_URL)) {
52+
if (!is_file($file) && !filter_var($file, FILTER_VALIDATE_URL)) {
5153
self::arrayToFile([], $file);
5254
}
5355

54-
$json = @file_get_contents($file);
55-
$array = json_decode($json, true);
56+
$json = @file_get_contents($file);
57+
$array = json_decode($json, true);
5658
$lastError = JsonLastError::check();
5759

5860
return $array === null || !is_null($lastError) ? false : $array;
@@ -70,10 +72,10 @@ public static function fileToArray($file)
7072
private static function createDirectory($file)
7173
{
7274
$basename = is_string($file) ? basename($file) : '';
73-
$path = str_replace($basename, '', $file);
75+
$path = str_replace($basename, '', $file);
7476

75-
if (! empty($path) && ! is_dir($path)) {
76-
if (! mkdir($path, 0755, true)) {
77+
if (!empty($path) && !is_dir($path)) {
78+
if (!mkdir($path, 0755, true)) {
7779
$message = 'Could not create directory in';
7880
throw new JsonException($message . ' ' . $path);
7981
}
@@ -86,7 +88,7 @@ private static function createDirectory($file)
8688
* @since 1.1.3
8789
*
8890
* @param string $file → path to the file
89-
* @param string $json → json string
91+
* @param string $json → JSON string
9092
*
9193
* @throws JsonException → couldn't create file
9294
*/

src/JsonLastError.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
/**
3-
* PHP simple library for managing Json files.
4+
* PHP simple library for managing JSON files.
45
*
5-
* @author Josantonius <hello@josantonius.com>
6-
* @copyright 2016 - 2018 (c) Josantonius - PHP-Json
6+
* @author Josantonius <hello@josantonius.dev>
7+
* @copyright 2016 (c) Josantonius
78
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
8-
* @link https://github.com/Josantonius/PHP-Json
9+
* @link https://github.com/josantonius/php-json
910
* @since 1.1.7
1011
*/
1112
namespace Josantonius\Json;
@@ -37,52 +38,53 @@ public static function check()
3738
public static function getCollection()
3839
{
3940
$collections = [
40-
JSON_ERROR_NONE => null,
41-
JSON_ERROR_DEPTH => [
42-
'message' => 'Maximum stack depth exceeded',
41+
JSON_ERROR_NONE => null,
42+
JSON_ERROR_DEPTH => [
43+
'message' => 'Maximum stack depth exceeded',
4344
'error-code' => 1,
4445
],
45-
JSON_ERROR_STATE_MISMATCH => [
46-
'message' => 'Underflow or the modes mismatch',
46+
JSON_ERROR_STATE_MISMATCH => [
47+
'message' => 'Underflow or the modes mismatch',
4748
'error-code' => 2,
4849
],
49-
JSON_ERROR_CTRL_CHAR => [
50-
'message' => 'Unexpected control char found',
50+
JSON_ERROR_CTRL_CHAR => [
51+
'message' => 'Unexpected control char found',
5152
'error-code' => 3,
5253
],
53-
JSON_ERROR_SYNTAX => [
54-
'message' => 'Syntax error, malformed JSON',
54+
JSON_ERROR_SYNTAX => [
55+
'message' => 'Syntax error, malformed JSON',
5556
'error-code' => 4,
5657
],
57-
JSON_ERROR_UTF8 => [
58-
'message' => 'Malformed UTF-8 characters',
58+
JSON_ERROR_UTF8 => [
59+
'message' => 'Malformed UTF-8 characters',
5960
'error-code' => 5,
6061
],
61-
JSON_ERROR_RECURSION => [
62-
'message' => 'Recursion error in value to be encoded',
62+
JSON_ERROR_RECURSION => [
63+
'message' => 'Recursion error in value to be encoded',
6364
'error-code' => 6,
6465
],
65-
JSON_ERROR_INF_OR_NAN => [
66-
'message' => 'Error NAN/INF in value to be encoded',
66+
JSON_ERROR_INF_OR_NAN => [
67+
'message' => 'Error NAN/INF in value to be encoded',
6768
'error-code' => 7,
6869
],
6970
JSON_ERROR_UNSUPPORTED_TYPE => [
70-
'message' => 'Type value given cannot be encoded',
71+
'message' => 'Type value given cannot be encoded',
7172
'error-code' => 8,
7273
],
73-
'default' => [
74-
'message' => 'Unknown error',
74+
'default' => [
75+
'message' => 'Unknown error',
7576
'error-code' => 999,
7677
],
7778
];
7879

7980
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
8081
$collections[JSON_ERROR_INVALID_PROPERTY_NAME] = [
81-
'message' => 'Name value given cannot be encoded',
82+
'message' => 'Name value given cannot be encoded',
8283
'error-code' => 9,
8384
];
85+
8486
$collections[JSON_ERROR_UTF16] = [
85-
'message' => 'Malformed UTF-16 characters',
87+
'message' => 'Malformed UTF-16 characters',
8688
'error-code' => 10,
8789
];
8890
}

tests/JsonLastErrorTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
/**
3-
* PHP simple library for managing Json files.
4+
* PHP simple library for managing JSON files.
45
*
5-
* @author Josantonius <hello@josantonius.com>
6-
* @copyright 2016 - 2018 (c) Josantonius - PHP-Json
6+
* @author Josantonius <hello@josantonius.dev>
7+
* @copyright 2016 (c) Josantonius
78
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
8-
* @link https://github.com/Josantonius/PHP-Json
9+
* @link https://github.com/josantonius/php-json
910
* @since 1.1.7
1011
*/
1112
namespace Josantonius\Json;
@@ -18,7 +19,7 @@
1819
class JsonLastErrorTest extends TestCase
1920
{
2021
/**
21-
* Json instance.
22+
* JSON instance.
2223
*
2324
* @var object
2425
*/
@@ -35,7 +36,7 @@ public function setUp()
3536
}
3637

3738
/**
38-
* Check if it is an instance of Json.
39+
* Check if it is an instance of JSON.
3940
*/
4041
public function testIsInstanceOfJson()
4142
{

tests/JsonTest.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
/**
3-
* PHP simple library for managing Json files.
4+
* PHP simple library for managing JSON files.
45
*
5-
* @author Josantonius <hello@josantonius.com>
6-
* @copyright 2016 - 2018 (c) Josantonius - PHP-Json
6+
* @author Josantonius <hello@josantonius.dev>
7+
* @copyright 2016 (c) Josantonius
78
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
8-
* @link https://github.com/Josantonius/PHP-Json
9+
* @link https://github.com/josantonius/php-json
910
* @since 1.1.3
1011
*/
1112
namespace Josantonius\Json;
@@ -14,12 +15,12 @@
1415
use PHPUnit\Framework\TestCase;
1516

1617
/**
17-
* Tests class for Json library.
18+
* Tests class for JSON library.
1819
*/
1920
class JsonTest extends TestCase
2021
{
2122
/**
22-
* Json instance.
23+
* JSON instance.
2324
*
2425
* @since 1.1.6
2526
*
@@ -40,7 +41,7 @@ public function setUp()
4041
}
4142

4243
/**
43-
* Check if it is an instance of Json.
44+
* Check if it is an instance of JSON.
4445
*
4546
* @since 1.1.6
4647
*/
@@ -57,13 +58,13 @@ public function testArrayToFile()
5758
$json = $this->json;
5859

5960
$array = [
60-
'name' => 'Josantonius',
61-
'email' => 'info@josantonius.com',
62-
'url' => 'https://github.com/josantonius/PHP-Json',
61+
'name' => 'Josantonius',
62+
'email' => 'hello@josantonius.dev',
63+
'url' => 'https://github.com/josantonius/php-json',
6364
];
6465

65-
$file = __DIR__ . '/filename.jsond';
66-
$result = $json::arrayToFile($array, $file);
66+
$file = __DIR__.'/filename.json';
67+
$result = $json::arrayToFile($array, $file);
6768

6869
$this->assertFileIsReadable($file);
6970

@@ -76,7 +77,7 @@ public function testArrayToFile()
7677
public function testArrayToFileCreateFileException()
7778
{
7879
$json = $this->json;
79-
80+
8081
$this->expectException(JsonException::class);
8182

8283
$json::arrayToFile([], '..');
@@ -88,8 +89,8 @@ public function testArrayToFileCreateFileException()
8889
public function testFileToArray()
8990
{
9091
$json = $this->json;
91-
92-
$file = __DIR__ . '/filename.jsond';
92+
93+
$file = __DIR__.'/filename.json';
9394

9495
$this->assertArrayHasKey('name', $json::fileToArray($file));
9596
$this->assertArrayHasKey('email', $json::fileToArray($file));
@@ -104,10 +105,10 @@ public function testFileToArray()
104105
public function testFileToArrayCreateFileException()
105106
{
106107
$json = $this->json;
107-
108+
108109
$this->expectException(JsonException::class);
109110

110-
$json::fileToArray(__DIR__ . '');
111+
$json::fileToArray(__DIR__.'');
111112
}
112113

113114
/**
@@ -116,8 +117,8 @@ public function testFileToArrayCreateFileException()
116117
public function testExternalFileToArray()
117118
{
118119
$json = $this->json;
119-
120-
$file = 'https://raw.githubusercontent.com/Josantonius/PHP-Json/master/composer.json';
120+
121+
$file = 'https://raw.githubusercontent.com/josantonius/php-json/master/composer.json';
121122

122123
$this->assertArrayHasKey('name', $json::fileToArray($file));
123124
$this->assertArrayHasKey('type', $json::fileToArray($file));
@@ -129,7 +130,7 @@ public function testExternalFileToArray()
129130
public function testExternalFileNonExistentToArray()
130131
{
131132
$json = $this->json;
132-
133+
133134
$file = 'https://raw.githubusercontent.com/composer.json';
134135

135136
$this->assertFalse($json::fileToArray($file));

0 commit comments

Comments
 (0)