File   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 2
cbo 2
dl 0
loc 48
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A create() 0 22 3
1
<?php
2
3
/**
4
 * @package Faker
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0
8
 */
9
10
namespace gplcart\modules\faker\models\generators;
11
12
use gplcart\modules\faker\models\Generator as FakerModuleGenerator;
13
14
/**
15
 * Manages basic behaviors and data related to files
16
 */
17
class File extends FakerModuleGenerator
18
{
19
20
    /**
21
     * Constructor
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
    }
27
28
    /**
29
     * Returns the generator name
30
     * @return string
31
     */
32
    public function getName()
33
    {
34
        return $this->translation->text('File');
35
    }
36
37
    /**
38
     * Generate a single file
39
     * @return bool
40
     */
41
    public function create()
42
    {
43
        $directory = GC_DIR_UPLOAD . '/faker';
44
45
        if (!file_exists($directory) && !mkdir($directory, 0775)) {
46
            return false;
47
        }
48
49
        $topics = (array) $this->config->get('module_faker_image_topics', array('abstract', 'technics'));
50
        $image = $this->faker->image($directory, 500, 500, $topics[array_rand($topics)], true);
51
52
        $field = array(
53
            'entity' => '',
54
            'entity_id' => '',
55
            'title' => $this->faker->text(50),
56
            'description' => $this->faker->text(100),
57
            'weight' => $this->faker->numberBetween(0, 20),
58
            'path' => str_replace('\\', '/', gplcart_file_relative($image))
59
        );
60
61
        return (bool) $this->file->add($field);
62
    }
63
64
}
65