OfacCreator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 48
ccs 0
cts 24
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createOfacFixtures() 0 10 2
A replaceContent() 0 8 1
B setter() 0 10 5
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 70.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace ADiaz\AML\OpenList\helpers;
4
5
/**
6
 * This file is part of the OpenList Parser utility.
7
 *
8
 * Class OfacCreator
9
 * This class helps to create a similar Unsc lists to be used for tests based in the last version of the list.
10
 *
11
 * @category PHP
12
 *
13
 * @author    Alberto Diaz <[email protected]>
14
 * @copyright 2016 Alberto Diaz <[email protected]>
15
 * @license   This source file is subject to the MIT license that is bundled
16
 *
17
 * @version Release: @package_version@
18
 *
19
 * @link http://tytem.com
20
 */
21
class OfacCreator
22
{
23
    /**
24
     * Get the file, replace the content and create the content.
25
     */
26
    public static function createOfacFixtures()
27
    {
28
        $sanctionFileContent = simplexml_load_string(file_get_contents('http://www.treasury.gov/ofac/downloads/sdn.xml'));
29
30
        foreach ($sanctionFileContent as $node) {
31
            self::replaceContent($node);
32
        }
33
34
        $sanctionFileContent->asXML(__DIR__.'/../../../tests/OpenList/fixtures/lists/usofac'.date('_Y-m-d').'.xml');
35
    }
36
37
    /**
38
     * Replace the content of the node.
39
     *
40
     * @param $node
41
     */
42
    protected static function replaceContent($node)
43
    {
44
        self::setter($node, 'firstName', Faker::getName());
45
        self::setter($node, 'lastName', Faker::getSurname());
46
        self::setter($node, 'sdnType', Faker::randomElement(['Entity', 'Individual']));
47
        self::setter($node, 'uid', mt_rand(10000, 900000));
48
        self::setter($node, 'title', Faker::randomElement(['Aerospace Engineer', 'Agricultural Engineer', 'Automotive Engineer', 'Biological Engineer', 'Biomedical Engineer']));
49
    }
50
51
    /**
52
     * set the attribute of the node only if exists.
53
     *
54
     * @param $node array
55
     * @param $property string
56
     * @param $value string|int
57
     */
58
    protected static function setter($node, $property, $value, $subProperty = false)
59
    {
60
61
        //if there is a sub-property and there is only one, replace it
62
        if ($subProperty && isset($node->$property->$subProperty) && count($node->$property->$subProperty) === 1) {
63
            $node->$property->$subProperty = $value;
64
        } elseif (property_exists($node, $property)) {
65
            $node->$property = $value;
66
        }
67
    }
68
}
69
70
OfacCreator::createOfacFixtures();
71