Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
78.57% |
22 / 28 |
|
50.00% |
3 / 6 |
CRAP | |
0.00% |
0 / 1 |
| config_text | |
78.57% |
22 / 28 |
|
50.00% |
3 / 6 |
15.93 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| add | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| update | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| remove | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| reverse | |
76.47% |
13 / 17 |
|
0.00% |
0 / 1 |
6.47 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\db\migration\tool; |
| 15 | |
| 16 | /** |
| 17 | * Migration config_text tool |
| 18 | */ |
| 19 | class config_text implements \phpbb\db\migration\tool\tool_interface |
| 20 | { |
| 21 | /** @var \phpbb\config\db_text */ |
| 22 | protected $config_text; |
| 23 | |
| 24 | /** |
| 25 | * Constructor |
| 26 | * |
| 27 | * @param \phpbb\config\db_text $config_text |
| 28 | */ |
| 29 | public function __construct(\phpbb\config\db_text $config_text) |
| 30 | { |
| 31 | $this->config_text = $config_text; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * {@inheritdoc} |
| 36 | */ |
| 37 | public function get_name() |
| 38 | { |
| 39 | return 'config_text'; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Add a config_text setting. |
| 44 | * |
| 45 | * @param string $config_name The name of the config_text setting |
| 46 | * you would like to add |
| 47 | * @param mixed $config_value The value of the config_text setting |
| 48 | * @return void |
| 49 | */ |
| 50 | public function add($config_name, $config_value) |
| 51 | { |
| 52 | if (!is_null($this->config_text->get($config_name))) |
| 53 | { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | $this->config_text->set($config_name, $config_value); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Update an existing config_text setting. |
| 62 | * |
| 63 | * @param string $config_name The name of the config_text setting you would |
| 64 | * like to update |
| 65 | * @param mixed $config_value The value of the config_text setting |
| 66 | * @return void |
| 67 | * @throws \phpbb\db\migration\exception |
| 68 | */ |
| 69 | public function update($config_name, $config_value) |
| 70 | { |
| 71 | if (is_null($this->config_text->get($config_name))) |
| 72 | { |
| 73 | throw new \phpbb\db\migration\exception('CONFIG_NOT_EXIST', $config_name); |
| 74 | } |
| 75 | |
| 76 | $this->config_text->set($config_name, $config_value); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Remove an existing config_text setting. |
| 81 | * |
| 82 | * @param string $config_name The name of the config_text setting you would |
| 83 | * like to remove |
| 84 | * @return void |
| 85 | */ |
| 86 | public function remove($config_name) |
| 87 | { |
| 88 | if (is_null($this->config_text->get($config_name))) |
| 89 | { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | $this->config_text->delete($config_name); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * {@inheritdoc} |
| 98 | */ |
| 99 | public function reverse() |
| 100 | { |
| 101 | $arguments = func_get_args(); |
| 102 | $original_call = array_shift($arguments); |
| 103 | |
| 104 | $call = false; |
| 105 | switch ($original_call) |
| 106 | { |
| 107 | case 'add': |
| 108 | $call = 'remove'; |
| 109 | break; |
| 110 | |
| 111 | case 'remove': |
| 112 | $call = 'add'; |
| 113 | if (count($arguments) == 1) |
| 114 | { |
| 115 | $arguments[] = ''; |
| 116 | } |
| 117 | break; |
| 118 | |
| 119 | case 'reverse': |
| 120 | // Reversing a reverse is just the call itself |
| 121 | $call = array_shift($arguments); |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | if ($call) |
| 126 | { |
| 127 | return call_user_func_array(array(&$this, $call), $arguments); |
| 128 | } |
| 129 | |
| 130 | return null; |
| 131 | } |
| 132 | } |