Skip to content

Commit

Permalink
[Lucene] Fix interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed May 18, 2012
1 parent a218998 commit 9796a6f
Show file tree
Hide file tree
Showing 50 changed files with 136 additions and 272 deletions.
30 changes: 14 additions & 16 deletions library/Zend/Search/Lucene/AbstractFSM.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

namespace Zend\Search\Lucene;

use Zend\Search\Lucene\Exception\InvalidArgumentException;

/**
* Abstract Finite State Machine
*
Expand Down Expand Up @@ -177,7 +175,7 @@ public function addState($state)
public function setState($state)
{
if (!isset($this->_states[$state])) {
throw new InvalidArgumentException('State \'' . $state . '\' is not on of the possible FSM states.');
throw new Exception\InvalidArgumentException('State \'' . $state . '\' is not on of the possible FSM states.');
}

$this->_currentState = $state;
Expand Down Expand Up @@ -248,20 +246,20 @@ public function addRules($rules)
public function addRule($sourceState, $input, $targetState, $inputAction = null)
{
if (!isset($this->_states[$sourceState])) {
throw new InvalidArgumentException('Undefined source state (' . $sourceState . ').');
throw new Exception\InvalidArgumentException('Undefined source state (' . $sourceState . ').');
}
if (!isset($this->_states[$targetState])) {
throw new InvalidArgumentException('Undefined target state (' . $targetState . ').');
throw new Exception\InvalidArgumentException('Undefined target state (' . $targetState . ').');
}
if (!isset($this->_inputAphabet[$input])) {
throw new InvalidArgumentException('Undefined input symbol (' . $input . ').');
throw new Exception\InvalidArgumentException('Undefined input symbol (' . $input . ').');
}

if (!isset($this->_rules[$sourceState])) {
$this->_rules[$sourceState] = array();
}
if (isset($this->_rules[$sourceState][$input])) {
throw new RuntimeException('Rule for {state,input} pair (' . $sourceState . ', '. $input . ') is already defined.');
throw new Exception\RuntimeException('Rule for {state,input} pair (' . $sourceState . ', '. $input . ') is already defined.');
}

$this->_rules[$sourceState][$input] = $targetState;
Expand All @@ -285,7 +283,7 @@ public function addRule($sourceState, $input, $targetState, $inputAction = null)
public function addEntryAction($state, FSMAction $action)
{
if (!isset($this->_states[$state])) {
throw new InvalidArgumentException('Undefined state (' . $state. ').');
throw new Exception\InvalidArgumentException('Undefined state (' . $state. ').');
}

if (!isset($this->_entryActions[$state])) {
Expand All @@ -307,7 +305,7 @@ public function addEntryAction($state, FSMAction $action)
public function addExitAction($state, FSMAction $action)
{
if (!isset($this->_states[$state])) {
throw new InvalidArgumentException('Undefined state (' . $state. ').');
throw new Exception\InvalidArgumentException('Undefined state (' . $state. ').');
}

if (!isset($this->_exitActions[$state])) {
Expand All @@ -330,10 +328,10 @@ public function addExitAction($state, FSMAction $action)
public function addInputAction($state, $inputSymbol, FSMAction $action)
{
if (!isset($this->_states[$state])) {
throw new InvalidArgumentException('Undefined state (' . $state. ').');
throw new Exception\InvalidArgumentException('Undefined state (' . $state. ').');
}
if (!isset($this->_inputAphabet[$inputSymbol])) {
throw new InvalidArgumentException('Undefined input symbol (' . $inputSymbol. ').');
throw new Exception\InvalidArgumentException('Undefined input symbol (' . $inputSymbol. ').');
}

if (!isset($this->_inputActions[$state])) {
Expand All @@ -359,10 +357,10 @@ public function addInputAction($state, $inputSymbol, FSMAction $action)
public function addTransitionAction($sourceState, $targetState, FSMAction $action)
{
if (!isset($this->_states[$sourceState])) {
throw new InvalidArgumentException('Undefined source state (' . $sourceState. ').');
throw new Exception\InvalidArgumentException('Undefined source state (' . $sourceState. ').');
}
if (!isset($this->_states[$targetState])) {
throw new InvalidArgumentException('Undefined source state (' . $targetState. ').');
throw new Exception\InvalidArgumentException('Undefined source state (' . $targetState. ').');
}

if (!isset($this->_transitionActions[$sourceState])) {
Expand All @@ -386,10 +384,10 @@ public function addTransitionAction($sourceState, $targetState, FSMAction $actio
public function process($input)
{
if (!isset($this->_rules[$this->_currentState])) {
throw new RuntimeException('There is no any rule for current state (' . $this->_currentState . ').');
throw new Exception\RuntimeException('There is no any rule for current state (' . $this->_currentState . ').');
}
if (!isset($this->_rules[$this->_currentState][$input])) {
throw new InvalidArgumentException('There is no any rule for {current state, input} pair (' . $this->_currentState . ', ' . $input . ').');
throw new Exception\InvalidArgumentException('There is no any rule for {current state, input} pair (' . $this->_currentState . ', ' . $input . ').');
}

$sourceState = $this->_currentState;
Expand Down Expand Up @@ -429,7 +427,7 @@ public function process($input)
public function reset()
{
if (count($this->_states) == 0) {
throw new RuntimeException('There is no any state defined for FSM.');
throw new Exception\RuntimeException('There is no any state defined for FSM.');
}

$this->_currentState = $this->_states[0];
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Search/Lucene/Document/AbstractOpenXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class AbstractOpenXML extends Document
/**
* Extract metadata from document
*
* @param ZipArchive $package ZipArchive AbstractOpenXML package
* @param \ZipArchive $package ZipArchive AbstractOpenXML package
* @return array Key-value pairs containing document meta data
*/
protected function extractMetaData(\ZipArchive $package)
Expand Down
10 changes: 5 additions & 5 deletions library/Zend/Search/Lucene/Document/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class HTML extends Document
/**
* Stored DOM representation
*
* @var DOMDocument
* @var \DOMDocument
*/
private $_doc;

/**
* Exclud nofollow links flag
* Exclude nofollow links flag
*
* If true then links with rel='nofollow' attribute are not included into
* document links.
Expand Down Expand Up @@ -212,7 +212,7 @@ public static function getExcludeNoFollowLinks()
*
* We should exclude scripts, which may be not included into comment tags, CDATA sections,
*
* @param DOMNode $node
* @param \DOMNode $node
* @param string &$text
*/
private function _retrieveNodeText(\DOMNode $node, &$text)
Expand Down Expand Up @@ -279,7 +279,7 @@ public static function loadHTMLFile($file, $storeContent = false, $defaultEncodi
/**
* Highlight text in text node
*
* @param DOMText $node
* @param \DOMText $node
* @param array $wordsToHighlight
* @param callback $callback Callback method, used to transform (highlighting) text.
* @param array $params Array of additionall callback parameters (first non-optional parameter is a text to transform)
Expand Down Expand Up @@ -343,7 +343,7 @@ protected function _highlightTextNode(\DOMText $node, $wordsToHighlight, $callba
/**
* highlight words in content of the specified node
*
* @param DOMNode $contextNode
* @param \DOMNode $contextNode
* @param array $wordsToHighlight
* @param callback $callback Callback method, used to transform (highlighting) text.
* @param array $params Array of additionall callback parameters (first non-optional parameter is a text to transform)
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Search/Lucene/Document/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private function __construct($fileName, $storeContent)
/**
* Parse rich text XML
*
* @param SimpleXMLElement $is
* @param \SimpleXMLElement $is
* @return string
*/
private function _parseRichText($is = null) {
Expand Down
8 changes: 4 additions & 4 deletions library/Zend/Search/Lucene/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Index implements SearchIndexInterface
/**
* Array of Zend_Search_Lucene_Index_SegmentInfo objects for current version of index.
*
* @var array \Zend\Search\Lucene\Index\SegmentInfo
* @var array|\Zend\Search\Lucene\Index\SegmentInfo
*/
private $_segmentInfos = array();

Expand Down Expand Up @@ -660,7 +660,7 @@ public function setMergeFactor($mergeFactor)
* Input is a string or Zend_Search_Lucene_Search_Query.
*
* @param \Zend\Search\Lucene\Search\QueryParser|string $query
* @return array \Zend\Search\Lucene\Search\QueryHit
* @return array|\Zend\Search\Lucene\Search\QueryHit
* @throws \Zend\Search\Lucene\Exception\InvalidArgumentException
* @throws \Zend\Search\Lucene\Exception\RuntimeException
*/
Expand Down Expand Up @@ -842,7 +842,7 @@ public function getFieldNames($indexed = false)
public function getDocument($id)
{
if ($id instanceof Search\QueryHit) {
/* @var $id Zend\Search\Lucene\Search\QueryHit */
/* @var $id \Zend\Search\Lucene\Search\QueryHit */
$id = $id->id;
}

Expand Down Expand Up @@ -1113,7 +1113,7 @@ public function hasDeletions()
public function delete($id)
{
if ($id instanceof Search\QueryHit) {
/* @var $id Zend\Search\Lucene\Search\QueryHit */
/* @var $id \Zend\Search\Lucene\Search\QueryHit */
$id = $id->id;
}

Expand Down
21 changes: 11 additions & 10 deletions library/Zend/Search/Lucene/Index/SegmentInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Zend\Search\Lucene,
Zend\Search\Lucene\Search\Similarity,
Zend\Search\Lucene\Storage\Directory,
Zend\Search\Lucene\Exception\ExceptionInterface,
Zend\Search\Lucene\Exception\RuntimeException,
Zend\Search\Lucene\Exception\InvalidFileFormatException,
Zend\Search\Lucene\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -153,7 +154,7 @@ class SegmentInfo implements TermsStreamInterface
/**
* File system adapter.
*
* @var \Zend\Search\Lucene\Storage\DirectoryInterface\Filesystem
* @var \Zend\Search\Lucene\Storage\Directory\DirectoryInterface
*/
private $_directory;

Expand Down Expand Up @@ -204,7 +205,7 @@ class SegmentInfo implements TermsStreamInterface
/**
* Zend_Search_Lucene_Index_SegmentInfo constructor
*
* @param \Zend\Search\Lucene\Storage\Directory $directory
* @param \Zend\Search\Lucene\Storage\Directory\DirectoryInterface $directory
* @param string $name
* @param integer $docCount
* @param integer $delGen
Expand All @@ -213,7 +214,7 @@ class SegmentInfo implements TermsStreamInterface
* @param boolean $isCompound
* @throws \Zend\Search\Lucene\Exception\RuntimeException
*/
public function __construct(Directory $directory, $name, $docCount, $delGen = 0, $docStoreOptions = null, $hasSingleNormFile = false, $isCompound = null)
public function __construct(Directory\DirectoryInterface $directory, $name, $docCount, $delGen = 0, $docStoreOptions = null, $hasSingleNormFile = false, $isCompound = null)
{
$this->_directory = $directory;
$this->_name = $name;
Expand Down Expand Up @@ -264,7 +265,7 @@ public function __construct(Directory $directory, $name, $docCount, $delGen = 0,

// Compound file is found
$this->_isCompound = true;
} catch (Lucene\Exception $e) {
} catch (ExceptionInterface $e) {
if (strpos($e->getMessage(), 'is not readable') !== false) {
// Compound file is not found or is not readable
$this->_isCompound = false;
Expand Down Expand Up @@ -390,7 +391,7 @@ private function _loadPre21DelFile()

return $deletions;
}
} catch(Lucene\Exception $e) {
} catch(ExceptionInterface $e) {
if (strpos($e->getMessage(), 'is not readable') === false) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
Expand Down Expand Up @@ -486,7 +487,7 @@ private function _load21DelFile()
* @param string $extension
* @param boolean $shareHandler
* @throws \Zend\Search\Lucene\Exception\InvalidFileFormatException
* @return \Zend\Search\Lucene\Storage\File
* @return \Zend\Search\Lucene\Storage\File\FileInterface
*/
public function openCompoundFile($extension, $shareHandler = true)
{
Expand Down Expand Up @@ -757,7 +758,7 @@ private function _cleanUpTermInfoCache()
/**
* Load terms dictionary index
*
* @throws \Zend\Search\Lucene\Exception
* @throws \Zend\Search\Lucene\Exception\ExceptionInterface
*/
private function _loadDictionaryIndex()
{
Expand Down Expand Up @@ -1617,7 +1618,7 @@ public function writeChanges()
/**
* Term Dictionary File object for stream like terms reading
*
* @var \Zend\Search\Lucene\Storage\File
* @var \Zend\Search\Lucene\Storage\File\FileInterface
*/
private $_tisFile = null;

Expand All @@ -1631,7 +1632,7 @@ public function writeChanges()
/**
* Frequencies File object for stream like terms reading
*
* @var \Zend\Search\Lucene\Storage\File
* @var \Zend\Search\Lucene\Storage\File\FileInterface
*/
private $_frqFile = null;

Expand All @@ -1645,7 +1646,7 @@ public function writeChanges()
/**
* Positions File object for stream like terms reading
*
* @var \Zend\Search\Lucene\Storage\File
* @var \Zend\Search\Lucene\Storage\File\FileInterface
*/
private $_prxFile = null;

Expand Down
9 changes: 5 additions & 4 deletions library/Zend/Search/Lucene/Index/SegmentMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

use Zend\Search\Lucene,
Zend\Search\Lucene\Document,
Zend\Search\Lucene\Exception\RuntimeException;
Zend\Search\Lucene\Exception\RuntimeException,
Zend\Search\Lucene\Storage\Directory;

/**
* @category Zend
Expand Down Expand Up @@ -51,7 +52,7 @@ class SegmentMerger
/**
* A set of segments to be merged
*
* @var array \Zend\Search\Lucene\Index\SegmentInfo
* @var array|\Zend\Search\Lucene\Index\SegmentInfo
*/
private $_segmentInfos = array();

Expand All @@ -78,10 +79,10 @@ class SegmentMerger
* Creates new segment merger with $directory as target to merge segments into
* and $name as a name of new segment
*
* @param \Zend\Search\Lucene\Storage\Directory $directory
* @param \Zend\Search\Lucene\Storage\Directory\DirectoryInterface $directory
* @param string $name
*/
public function __construct($directory, $name)
public function __construct(Directory\DirectoryInterface $directory, $name)
{
/** \Zend\Search\Lucene\Index\SegmentWriter\StreamWriter */
$this->_writer = new SegmentWriter\StreamWriter($directory, $name);
Expand Down
Loading

0 comments on commit 9796a6f

Please sign in to comment.