Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Introducing a MetaFilterList #56
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Feb 14, 2016
1 parent 0b28991 commit 37568f0
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 0 deletions.
98 changes: 98 additions & 0 deletions inc/Import/Data/MetaFilterList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Data;

use
W2M\Import\Filter;

/**
* Class MetaFilterList
*
* Manages a list of Filter\ValueFilterableInterface for each type:meta-key pair
*
* @package W2M\Import\Data
*/
class MetaFilterList implements MetaFilterListInterface {

/**
* @var Filter\ValueFilterableInterface[][]
*/
private $filters;

public function __construct() {

$this->filters = [
'comment' => [],
'post' => [],
'term' => [],
'user' => []
];
}

/**
* @param string $type
* @param string $key
* @param Filter\ValueFilterableInterface $filter
*
* @return bool
*/
public function push_filter( $type, $key, Filter\ValueFilterableInterface $filter ) {

$this->setup_list( $type, $key );
$index = spl_object_hash( $filter );
if ( isset( $this->filters[ $type ][ $key ][ $index ] ) )
return FALSE;

$this->filters[ $type ][ $key ][ $index ] = $filter;

return TRUE;
}

/**
* @param string $type
* @param string $key
* @param Filter\ValueFilterableInterface $filter
*
* @return bool
*/
public function pop_filter( $type, $key, Filter\ValueFilterableInterface $filter ) {

$this->setup_list( $type, $key );
$index = spl_object_hash( $filter );
if ( isset( $this->filters[ $type ][ $key ][ $index ] ) ) {
unset( $this->filters[ $type ][ $key ][ $index ] );

return TRUE;
}

return FALSE;
}

/**
* @param string $type
* @param string $key
*
* @return Filter\ValueFilterableInterface[]
*/
public function get_filters( $type, $key ) {

$this->setup_list( $type, $key );

return isset( $this->filters[ $type ][ $key ] )
? $this->filters[ $type ][ $key ]
: [];
}

/**
* @param string $type
* @param string $key
*/
private function setup_list( $type, $key ) {

if ( isset( $this->filters[ $type ][ $key ] ) )
return;

$this->filters[ $type ][ $key ] = [];
}

}
42 changes: 42 additions & 0 deletions inc/Import/Data/MetaFilterListInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Data;

use
W2M\Import\Filter;

/**
* Interface MetaFilterListInterface
*
* Manages a list of Filter\ValueFilterableInterface for each type:meta-key pair
*
* @package W2M\Import\Data
*/
interface MetaFilterListInterface {

/**
* @param string $type
* @param string $key
* @param Filter\ValueFilterableInterface $filter
*
* @return bool
*/
public function push_filter( $type, $key, Filter\ValueFilterableInterface $filter );

/**
* @param string $type
* @param string $key
* @param Filter\ValueFilterableInterface $filter
*
* @return bool
*/
public function pop_filter( $type, $key, Filter\ValueFilterableInterface $filter );

/**
* @param string $type
* @param string $key
*
* @return Filter\ValueFilterableInterface[]
*/
public function get_filters( $type, $key );
}
28 changes: 28 additions & 0 deletions tests/phpunit/Unit/Import/Data/MetaFilterListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Test\Unit\Import\Data;

use
W2M\Import\Filter,
W2M\Test\Helper;

class MetaFilterListTest extends Helper\MonkeyTestCase {

public function test_push_filter() {

// Todo: Write tests
$this->markTestIncomplete( 'Under construction' );
}

public function test_pop_filter() {

// Todo: Write tests
$this->markTestIncomplete( 'Under construction' );
}

public function test_get_filters() {

// Todo: Write tests
$this->markTestIncomplete( 'Under construction' );
}
}

0 comments on commit 37568f0

Please sign in to comment.