Skip to content

Commit f6cb1d1

Browse files
committed
perf: delete deprecated methods
Comments were also refactored. #17
1 parent c4b98b9 commit f6cb1d1

File tree

1 file changed

+10
-69
lines changed

1 file changed

+10
-69
lines changed

src/Json.php

Lines changed: 10 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
declare(strict_types=1);
44

5-
/**
6-
* PHP simple library for managing JSON files.
5+
/*
6+
* This file is part of https://github.com/josantonius/php-json repository.
7+
*
8+
* (c) Josantonius <hello@josantonius.dev>
79
*
8-
* @author Josantonius <hello@josantonius.dev>
9-
* @copyright 2016 (c) Josantonius
10-
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
11-
* @link https://github.com/josantonius/php-json
12-
* @since 1.0.0
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
1312
*/
1413

1514
namespace Josantonius\Json;
@@ -20,18 +19,17 @@
2019
use Josantonius\Json\Exception\JsonErrorException;
2120
use Josantonius\Json\Exception\UnavailableMethodException;
2221

22+
/**
23+
* PHP simple library for managing JSON files.
24+
*/
2325
class Json
2426
{
2527
/**
2628
* If the file path is a URL.
27-
*
28-
* @since 2.0.0
2929
*/
3030
private bool $isUrl;
3131

3232
/**
33-
* @since 2.0.0
34-
*
3533
* @throws CreateDirectoryException
3634
* @throws CreateFileException
3735
* @throws JsonErrorException
@@ -48,8 +46,6 @@ public function __construct(private string $filepath)
4846
/**
4947
* Get the content of the JSON file or a remote JSON file.
5048
*
51-
* @since 2.0.0
52-
*
5349
* @throws GetFileException
5450
* @throws JsonErrorException
5551
*/
@@ -61,8 +57,6 @@ public function get(): array
6157
/**
6258
* Set the content of the JSON file.
6359
*
64-
* @since 2.0.0
65-
*
6660
* @throws CreateFileException
6761
* @throws JsonErrorException
6862
* @throws UnavailableMethodException
@@ -75,8 +69,6 @@ public function set(array|object $content): void
7569
/**
7670
* Merge into JSON file.
7771
*
78-
* @since 2.0.0
79-
*
8072
* @throws CreateFileException
8173
* @throws GetFileException
8274
* @throws JsonErrorException
@@ -94,8 +86,6 @@ public function merge(array|object $content): array
9486
/**
9587
* Push on the JSON file.
9688
*
97-
* @since 2.0.0
98-
*
9989
* @throws CreateFileException
10090
* @throws GetFileException
10191
* @throws JsonErrorException
@@ -112,48 +102,9 @@ public function push(array|object $content): array
112102
return $data;
113103
}
114104

115-
/**
116-
* Create JSON file from array.
117-
*
118-
* @deprecated
119-
*
120-
* @throws CreateFileException
121-
* @throws JsonErrorException
122-
* @throws UnavailableMethodException
123-
*/
124-
public static function arrayToFile(array|object $array, string $file): bool
125-
{
126-
$message = 'The "arrayToFile" method is deprecated and will be removed. Use "set" instead.';
127-
$url = 'More information at: https://github.com/josantonius/php-json.';
128-
trigger_error($message . ' ' . $url, E_USER_DEPRECATED);
129-
130-
(new Json($file))->set($array);
131-
132-
return true;
133-
}
134-
135-
/**
136-
* Get the content of the JSON file or a remote JSON file.
137-
*
138-
* @deprecated
139-
*
140-
* @throws GetFileException
141-
* @throws JsonErrorException
142-
*/
143-
public static function fileToArray($file): array
144-
{
145-
$message = 'The "fileToArray" method is deprecated and will be removed. Use "get" instead.';
146-
$url = 'More information at: https://github.com/josantonius/php-json.';
147-
trigger_error($message . ' ' . $url, E_USER_DEPRECATED);
148-
149-
return (new Json($file))->get();
150-
}
151-
152105
/**
153106
* Create file if not exists.
154107
*
155-
* @since 2.0.0
156-
*
157108
* @throws CreateDirectoryException
158109
* @throws CreateFileException
159110
* @throws JsonErrorException
@@ -169,8 +120,6 @@ private function createFileIfNotExists(): void
169120
/**
170121
* Create directory if not exists.
171122
*
172-
* @since 2.0.0
173-
*
174123
* @throws CreateDirectoryException
175124
*/
176125
private function createDirIfNotExists(): void
@@ -185,8 +134,6 @@ private function createDirIfNotExists(): void
185134
/**
186135
* Get the content of the JSON file or a remote JSON file.
187136
*
188-
* @since 2.0.0
189-
*
190137
* @throws GetFileException
191138
* @throws JsonErrorException
192139
*/
@@ -208,8 +155,6 @@ private function getFileContents(): array
208155
/**
209156
* Save content in JSON file.
210157
*
211-
* @since 2.0.0
212-
*
213158
* @throws CreateFileException
214159
* @throws JsonErrorException
215160
*/
@@ -227,8 +172,6 @@ private function saveToJsonFile(array|object $array): void
227172
/**
228173
* Check for JSON errors.
229174
*
230-
* @since 2.0.0
231-
*
232175
* @throws JsonErrorException
233176
*/
234177
private function checkJsonLastError(): void
@@ -241,14 +184,12 @@ private function checkJsonLastError(): void
241184
/**
242185
* Throw exception if the method is not available for remote JSON files.
243186
*
244-
* @since 2.0.0
245-
*
246187
* @throws UnavailableMethodException
247188
*/
248189
private function throwUnavailableMethodException(): void
249190
{
250191
$method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
251-
192+
252193
throw new UnavailableMethodException($method);
253194
}
254195
}

0 commit comments

Comments
 (0)