Passed
Push — master ( 1d6111...796ecb )
by Emmanuel
04:33
created

Json::jsonWordsObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
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\Generator;
24
use Faker\Provider\Lorem;
25
26
/**
27
 * Class Json.
28
 */
29
class Json extends Lorem
30
{
31
      /**
32
       * Generate a json list containing words
33
       *
34
       * @example ["ut", "eaque", "rerum", "voluptatem"]
35
       * @param  integer      $nb     how many words to return
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  integer      $nb     how many words to return
53
       * @return array|string
54
       */
55
      public static function jsonWordsObject($nb = 3)
56
      {
57
          $words = [];
58
          for ($i=0; $i < $nb; $i++) {
59
              $word = static::word();
60
              $words [\substr($word, 1, 1) . $i] = $word;
61
          }
62
63
          return json_encode($words);
64
      }
65
}
66