Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoTableSchema
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 newFromDBString
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
 toDBString
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 removeField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Ideally this would probably implement the "Iterator" interface, but that
5 * seems like too much work for the limited usage this class gets.
6 *
7 * @author Yaron Koren
8 * @ingroup Cargo
9 */
10
11class CargoTableSchema {
12
13    public $mFieldDescriptions = [];
14
15    public static function newFromDBString( $dbString ) {
16        $tableSchema = new CargoTableSchema();
17        $tableSchemaDBArray = unserialize( $dbString );
18        if ( !is_array( $tableSchemaDBArray ) ) {
19            throw new MWException( "Invalid field information found for table." );
20        }
21        foreach ( $tableSchemaDBArray as $fieldName => $fieldDBArray ) {
22            $tableSchema->mFieldDescriptions[$fieldName] = CargoFieldDescription::newFromDBArray(
23                $fieldDBArray );
24        }
25        return $tableSchema;
26    }
27
28    public function toDBString() {
29        $tableSchemaDBArray = [];
30        foreach ( $this->mFieldDescriptions as $fieldName => $fieldDesc ) {
31            $tableSchemaDBArray[$fieldName] = $fieldDesc->toDBArray();
32        }
33        return serialize( $tableSchemaDBArray );
34    }
35
36    public function removeField( $fieldName ) {
37        unset( $this->mFieldDescriptions[$fieldName] );
38    }
39
40    public function addField( $fieldName, $fieldDescription ) {
41        $this->mFieldDescriptions[$fieldName] = $fieldDescription;
42    }
43
44}