|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
namespace ADiaz\AML\OpenList\helpers; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class UnscCreator |
|
7
|
|
|
* This class helps to create a similar Unsc lists to be used for tests based in the last version of the list. |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of the OpenList Parser utility. |
|
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 UnscCreator |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Get the file, replace the content and create the content. |
|
25
|
|
|
*/ |
|
26
|
|
|
public static function createUnscFixtures() |
|
27
|
|
|
{ |
|
28
|
|
|
$sanctionFileContent = simplexml_load_string(file_get_contents('https://www.un.org/sc/suborg/sites/www.un.org.sc.suborg/files/consolidated.xml')); |
|
29
|
|
|
|
|
30
|
|
|
$individuals = $sanctionFileContent->xpath('//INDIVIDUAL'); |
|
31
|
|
|
|
|
32
|
|
|
foreach ($individuals as $individual) { |
|
33
|
|
|
self::replaceContent($individual); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$entities = $sanctionFileContent->xpath('//ENTITY'); |
|
37
|
|
|
|
|
38
|
|
|
foreach ($entities as $entity) { |
|
39
|
|
|
self::replaceContent($entity); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$sanctionFileContent->asXML(__DIR__.'/../../../tests/OpenList/fixtures/lists/unsc'.date('_Y-m-d').'.xml'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Replace the content of the node. |
|
47
|
|
|
* |
|
48
|
|
|
* @param $node |
|
49
|
|
|
*/ |
|
50
|
|
|
protected static function replaceContent($node) |
|
51
|
|
|
{ |
|
52
|
|
|
self::setter($node, 'FIRST_NAME', Faker::getName()); |
|
53
|
|
|
self::setter($node, 'SECOND_NAME', Faker::getSurname()); |
|
54
|
|
|
self::setter($node, 'THIRD_NAME', Faker::getSurname()); |
|
55
|
|
|
self::setter($node, 'FOURTH_NAME', Faker::getSurname()); |
|
56
|
|
|
self::setter($node, 'NAME_ORIGINAL_SCRIPT', Faker::getName()); |
|
57
|
|
|
self::setter($node, 'COMMENTS1', Faker::getString(20)); |
|
58
|
|
|
self::setter($node, 'LISTED_ON', Faker::getDate()); |
|
59
|
|
|
self::setter($node, 'REFERENCE_NUMBER', mt_rand(1000000, 9999999)); |
|
60
|
|
|
self::setter($node, 'DATAID', mt_rand(10000, 99999)); |
|
61
|
|
|
self::setter($node, 'VERSIONNUM', mt_rand(1, 99)); |
|
62
|
|
|
self::setter($node, 'UN_LIST_TYPE', Faker::getCountry()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* set the attribute of the node only if exists. |
|
67
|
|
|
* |
|
68
|
|
|
* @param $node array |
|
69
|
|
|
* @param $property string |
|
70
|
|
|
* @param $value string|int |
|
71
|
|
|
*/ |
|
72
|
|
|
protected static function setter($node, $property, $value) |
|
73
|
|
|
{ |
|
74
|
|
|
if (property_exists($node, $property)) { |
|
75
|
|
|
$node->$property = $value; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
UnscCreator::createUnscFixtures(); |
|
81
|
|
|
|
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.