Completed
Push — master ( 14d2bd...06e609 )
by mw
81:37 queued 59:24
created

includes/storage/SQLStore/SMW_DIHandler_Bool.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @ingroup SMWDataItemsHandlers
4
 */
5
6
/**
7
 * This class implements Store access to Boolean data items.
8
 *
9
 * @since 1.8
10
 *
11
 * @author Nischay Nahata
12
 * @ingroup SMWDataItemsHandlers
13
 */
14
class SMWDIHandlerBoolean extends SMWDataItemHandler {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
16
	/**
17
	 * Method to return array of fields for a DI type
18
	 *
19
	 * @return array
20
	 */
21 26
	public function getTableFields() {
22 26
		return array( 'o_value' => 'b' );
23
	}
24
25
	/**
26
	 * @see SMWDataItemHandler::getFetchFields()
27
	 *
28
	 * @since 1.8
29
	 * @return array
30
	 */
31 5
	public function getFetchFields() {
32 5
		return array( 'o_value' => 'b' );
33
	}
34
35
	/**
36
	 * Method to return an array of fields=>values for a DataItem
37
	 *
38
	 * @return array
39
	 */
40
	public function getWhereConds( SMWDataItem $dataItem ) {
41
		return array(
42
			'o_value' => $dataItem->getBoolean() ? 1 : 0,
43
		);
44
	}
45
46
	/**
47
	 * Method to return an array of fields=>values for a DataItem
48
	 * This array is used to perform all insert operations into the DB
49
	 * To optimize return minimum fields having indexes
50
	 *
51
	 * @return array
52
	 */
53 12
	public function getInsertValues( SMWDataItem $dataItem ) {
54
		return array(
55 12
			'o_value' => $dataItem->getBoolean() ? 1 : 0,
56
		);
57
	}
58
59
	/**
60
	 * Method to return the field used to select this type of DataItem
61
	 * @since 1.8
62
	 * @return string
63
	 */
64 7
	public function getIndexField() {
65 7
		return 'o_value';
66
	}
67
68
	/**
69
	 * Method to return the field used to select this type of DataItem
70
	 * using the label
71
	 * @since 1.8
72
	 * @return string
73
	 */
74 5
	public function getLabelField() {
75 5
		return 'o_value';
76
	}
77
78
	/**
79
	 * Method to create a dataitem from an array of DB keys.
80
	 *
81
	 * @since 1.8
82
	 * @param array|string $dbkeys should be a string here
83
	 *
84
	 * @return SMWDataItem
85
	 */
86 3
	public function dataItemFromDBKeys( $dbkeys ) {
87 3
		global $wgDBtype;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
88
89
		//PgSQL returns as t and f and need special handling http://archives.postgresql.org/pgsql-php/2010-02/msg00005.php
90 3
		if ( $wgDBtype == 'postgres' ) {
91
			$value = ( $dbkeys == 't' );
92
		} else {
93 3
			$value = ( $dbkeys == '1' );
94
		}
95
96 3
		return new SMWDIBoolean( $value );
97
	}
98
}
99