Json::jsonWordsList()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * neuralyzer : Data Anonymization Library and CLI Tool
7
 *
8
 * PHP Version 7.2
9
 *
10
 * @author    Emmanuel Dyan
11
 *
12
 * @copyright 2020 Emmanuel Dyan
13
 *
14
 * @package edyan/neuralyzer
15
 *
16
 * @license GNU General Public License v2.0
17
 *
18
 * @link https://github.com/edyan/neuralyzer
19
 */
20
21
namespace Edyan\Neuralyzer\Faker\Provider;
22
23
use Faker\Provider\Lorem;
24
25
/**
26
 * Class Json.
27
 */
28
class Json extends Lorem
29
{
30
    /**
31
     * Generate a json list containing words
32
     *
33
     * @example ["ut", "eaque", "rerum", "voluptatem"]
34
     * @param  int      $nb     how many words to return
35
     *
36
     * @return array|string
37
     */
38
    public static function jsonWordsList($nb = 3)
39
    {
40
        $words = [];
41
        for ($i = 0; $i < $nb; $i++) {
42
            $words[] = static::word();
43
        }
44
45
        return json_encode($words);
46
    }
47
48
    /**
49
     * Generate a json containing words as an object
50
     *
51
     * @example ["ut", "eaque", "rerum", "voluptatem"]
52
     * @param  int      $nb     how many words to return
53
     *
54
     * @return array|string
55
     */
56
    public static function jsonWordsObject($nb = 3)
57
    {
58
        $words = [];
59
        for ($i = 0; $i < $nb; $i++) {
60
            $word = static::word();
61
            $words[\substr($word, 1, 1) . $i] = $word;
62
        }
63
64
        return json_encode($words);
65
    }
66
}
67