FIX Run phpcbf automated linting to fix PSR-2 code styles, add PSR-4 autoloader

This commit is contained in:
Robbie Averill 2017-11-15 09:48:52 +13:00
parent 1080d6444a
commit e590132967
44 changed files with 208 additions and 112 deletions

View File

@ -1,7 +1,9 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\DataObject;
/**
* Some additional introspection tools that are used often by the fulltext search code
*/

View File

@ -5,11 +5,13 @@ namespace SilverStripe\FullTextSearch\Captures;
use SilverStripe\ORM\Connect\MySQLDatabase;
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
class SearchManipulateCapture_MySQLDatabase extends MySQLDatabase {
class SearchManipulateCapture_MySQLDatabase extends MySQLDatabase
{
public $isManipulationCapture = true;
public function manipulate($manipulation) {
public function manipulate($manipulation)
{
$res = parent::manipulate($manipulation);
SearchUpdater::handle_manipulation($manipulation);
return $res;

View File

@ -9,11 +9,13 @@ if (!class_exists('PostgreSQLDatabase')) {
return;
}
class SearchManipulateCapture_PostgreSQLDatabase extends PostgreSQLDatabase {
class SearchManipulateCapture_PostgreSQLDatabase extends PostgreSQLDatabase
{
public $isManipulationCapture = true;
public function manipulate($manipulation) {
public function manipulate($manipulation)
{
$res = parent::manipulate($manipulation);
SearchUpdater::handle_manipulation($manipulation);
return $res;

View File

@ -9,11 +9,13 @@ if (!class_exists('SQLite3Database')) {
return;
}
class SearchManipulateCapture_SQLite3Database extends SQLite3Database {
class SearchManipulateCapture_SQLite3Database extends SQLite3Database
{
public $isManipulationCapture = true;
public function manipulate($manipulation) {
public function manipulate($manipulation)
{
$res = parent::manipulate($manipulation);
SearchUpdater::handle_manipulation($manipulation);
return $res;

View File

@ -124,5 +124,3 @@ class SearchQuery extends ViewableData
return "Search Query\n";
}
}

View File

@ -127,8 +127,7 @@ class SearchUpdater
'command' => $command,
'fields' => array()
);
}
// Otherwise update the class label if it's more specific than the currently recorded one
} // Otherwise update the class label if it's more specific than the currently recorded one
elseif (is_subclass_of($class, $writes[$key]['class'])) {
$writes[$key]['class'] = $class;
}

View File

@ -219,7 +219,8 @@ abstract class SearchVariant
* @param string $name Field name
* @param array $field Field spec
*/
protected function addFilterField($index, $name, $field) {
protected function addFilterField($index, $name, $field)
{
// If field already exists, make sure to merge origin / base fields
if (isset($index->filterFields[$name])) {
$field['base'] = $this->mergeClasses(
@ -244,7 +245,8 @@ abstract class SearchVariant
* @param array|string $right Right class(es)
* @return array|string List of classes, or single class
*/
protected function mergeClasses($left, $right) {
protected function mergeClasses($left, $right)
{
// Merge together and remove dupes
if (!is_array($left)) {
$left = array($left);
@ -261,4 +263,3 @@ abstract class SearchVariant
return $merged;
}
}

View File

@ -109,12 +109,10 @@ class SearchVariantSubsites extends SearchVariant
if (isset($write['fields']['SiteTree:SubsiteID'])) {
$subsitesForWrite = array($write['fields']['SiteTree:SubsiteID']);
}
// files in subsite 0 should be in all subsites as they are global
} // files in subsite 0 should be in all subsites as they are global
elseif (isset($write['fields']['File:SubsiteID']) && intval($write['fields']['File:SubsiteID']) !== 0) {
$subsitesForWrite = array($write['fields']['File:SubsiteID']);
}
else {
} else {
$subsitesForWrite = $subsites;
}

View File

@ -121,7 +121,10 @@ class Solr
if (!self::$service_singleton) {
self::$service_singleton = Object::create(
$options['service'], $options['host'], $options['port'], $options['path']
$options['service'],
$options['host'],
$options['port'],
$options['path']
);
}

View File

@ -1,6 +1,7 @@
<?php
namespace SilverStripe\FullTextSearch\Solr;
Solr::include_client_api();
use SilverStripe\Control\Director;
@ -493,7 +494,8 @@ abstract class SolrIndex extends SearchIndex
* @param array|string $base Class or list of base classes
* @return bool
*/
protected function classIs($class, $base) {
protected function classIs($class, $base)
{
if (is_array($base)) {
foreach ($base as $nextBase) {
if ($this->classIs($class, $nextBase)) {

View File

@ -34,7 +34,11 @@ abstract class SolrReindexBase implements SolrReindexHandler
* @param string $classes
*/
protected function processIndex(
LoggerInterface $logger, SolrIndex $indexInstance, $batchSize, $taskName, $classes = null
LoggerInterface $logger,
SolrIndex $indexInstance,
$batchSize,
$taskName,
$classes = null
) {
// Filter classes for this index
$indexClasses = $this->getClassesForIndex($indexInstance, $classes);
@ -87,8 +91,13 @@ abstract class SolrReindexBase implements SolrReindexHandler
* @param string $taskName
*/
protected function processVariant(
LoggerInterface $logger, SolrIndex $indexInstance, $state,
$class, $includeSubclasses, $batchSize, $taskName
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$includeSubclasses,
$batchSize,
$taskName
) {
// Set state
SearchVariant::activate_state($state);
@ -127,7 +136,13 @@ abstract class SolrReindexBase implements SolrReindexHandler
* @param string $taskName Name of task script to run
*/
abstract protected function processGroup(
LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group,
$taskName
);
/**
@ -144,7 +159,12 @@ abstract class SolrReindexBase implements SolrReindexHandler
* @param int $group
*/
public function runGroup(
LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group
) {
// Set time limit and state
Environment::increaseTimeLimitTo();

View File

@ -21,7 +21,11 @@ class SolrReindexImmediateHandler extends SolrReindexBase
}
protected function processIndex(
LoggerInterface $logger, SolrIndex $indexInstance, $batchSize, $taskName, $classes = null
LoggerInterface $logger,
SolrIndex $indexInstance,
$batchSize,
$taskName,
$classes = null
) {
parent::processIndex($logger, $indexInstance, $batchSize, $taskName, $classes);
@ -46,7 +50,13 @@ class SolrReindexImmediateHandler extends SolrReindexBase
* @param string $taskName Name of task script to run
*/
protected function processGroup(
LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group,
$taskName
) {
// Build state
$statevar = json_encode($state);

View File

@ -85,12 +85,22 @@ class SolrReindexQueuedHandler extends SolrReindexBase
}
protected function processGroup(
LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group,
$taskName
) {
// Trigger another job for this group
$job = Injector::inst()->create(
SolrReindexGroupQueuedJob::class,
get_class($indexInstance), $state, $class, $groups, $group
get_class($indexInstance),
$state,
$class,
$groups,
$group
);
$this
->getQueuedJobService()
@ -101,7 +111,12 @@ class SolrReindexQueuedHandler extends SolrReindexBase
}
public function runGroup(
LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group
) {
parent::runGroup($logger, $indexInstance, $state, $class, $groups, $group);

View File

@ -2,7 +2,6 @@
namespace SilverStripe\FullTextSearch\Solr\Services;
class Solr3Service_Core extends SolrService_Core
{
}

View File

@ -25,8 +25,12 @@ class Solr4Service_Core extends SolrService_Core
* @inheritdoc
* @see Solr4Service_Core::addDocuments
*/
public function addDocument(\Apache_Solr_Document $document, $allowDups = false,
$overwritePending = true, $overwriteCommitted = true, $commitWithin = 0
public function addDocument(
\Apache_Solr_Document $document,
$allowDups = false,
$overwritePending = true,
$overwriteCommitted = true,
$commitWithin = 0
) {
return $this->addDocuments(array($document), $allowDups, $overwritePending, $overwriteCommitted, $commitWithin);
}
@ -35,8 +39,12 @@ class Solr4Service_Core extends SolrService_Core
* Solr 4.0 compat http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22add.22
* Remove allowDups, overwritePending and overwriteComitted
*/
public function addDocuments($documents, $allowDups = false, $overwritePending = true,
$overwriteCommitted = true, $commitWithin = 0
public function addDocuments(
$documents,
$allowDups = false,
$overwritePending = true,
$overwriteCommitted = true,
$commitWithin = 0
) {
$overwriteVal = $allowDups ? 'false' : 'true';
$commitWithin = (int) $commitWithin;

View File

@ -1,5 +1,6 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Stores;
/**
* Class SolrConfigStore
*
@ -30,7 +31,3 @@ interface SolrConfigStore
*/
public function instanceDir($index);
}

View File

@ -2,7 +2,6 @@
namespace SilverStripe\FullTextSearch\Solr\Stores;
/**
* Class SolrConfigStore_File
*

View File

@ -1,9 +1,11 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Tasks;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use Psr\Log\LoggerInterface;
use SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory;
/**
* Abstract class for build tasks
*/

View File

@ -1,5 +1,6 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Tasks;
use Exception;
use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Solr\Solr;

View File

@ -1,5 +1,6 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Tasks;
use ReflectionClass;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injector;

View File

@ -1,6 +1,8 @@
<?php
namespace SilverStripe\FullTextSearch\Utils;
use Iterator;
class MultipleArrayIterator implements Iterator
{
protected $arrays;

View File

@ -1,5 +1,6 @@
<?php
namespace SilverStripe\FullTextSearch\Utils;
class WebDAV
{
public static function curl_init($url, $method)

View File

@ -29,6 +29,12 @@
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"SilverStripe\\FullTextSearch\\": "code/",
"SilverStripe\\FullTextSearch\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
@ -38,5 +44,5 @@
"silverstripe/fulltextsearch-localsolr": "Adds a ready-to-use local Solr server for initial development"
},
"minimum-stability": "dev",
"prefer-stable": "true"
"prefer-stable": true
}

View File

@ -1,16 +1,18 @@
<?php
use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\FullTextSearch;
use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateProcessor;
use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateImmediateProcessor;
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_Container;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_HasOne;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_HasMany;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_Index;
use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateProcessor;
use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateImmediateProcessor;
class SearchUpdaterTest extends SapphireTest
{
@ -74,7 +76,9 @@ class SearchUpdaterTest extends SapphireTest
$added = self::$index->getAdded(array('ID'));
// Some databases don't output $added in a consistent order; that's okay
usort($added, function ($a, $b) {return $a['ID']-$b['ID']; });
usort($added, function ($a, $b) {
return $a['ID']-$b['ID'];
});
$this->assertEquals($added, array(
array('ID' => $container1->ID),
@ -93,7 +97,9 @@ class SearchUpdaterTest extends SapphireTest
$added = self::$index->getAdded(array('ID'));
// Some databases don't output $added in a consistent order; that's okay
usort($added, function ($a, $b) {return $a['ID']-$b['ID']; });
usort($added, function ($a, $b) {
return $a['ID']-$b['ID'];
});
$this->assertEquals($added, array(
array('ID' => $container1->ID),

View File

@ -1,13 +1,13 @@
<?php
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex_Recording;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex_Recording;
use SilverStripe\FullTextSearch\Tests\SearchVariantSiteTreeSubsitesPolyhomeTest\SearchVariantSiteTreeSubsitesPolyhomeTest_Index;
use SilverStripe\FullTextSearch\Tests\SearchVariantSiteTreeSubsitesPolyhomeTest\SearchVariantSiteTreeSubsitesPolyhomeTest_Item;
class SearchVariantSiteTreeSubsitesPolyhomeTest extends SapphireTest
{
private static $index = null;

View File

@ -1,5 +1,7 @@
<?php
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Dev\SapphireTest;
class SearchVariantSubsiteTest extends SapphireTest
@ -86,7 +88,5 @@ class SearchVariantSubsiteTest extends SapphireTest
//subsite filter has been modified with our arbitrary test value. The second value is not set
//this proves that the query has not been altered by the variant
$this->assertEquals(2, $query->require['_subsite'][0]);
}
}

View File

@ -1,8 +1,10 @@
<?php
use SilverStripe\Dev\SapphireTest;
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\FullTextSearch;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex_Recording;
use SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned;

View File

@ -16,4 +16,3 @@ class Solr4ServiceTest_RecordingService extends Solr4Service_Core
return $url;
}
}

View File

@ -1,5 +1,7 @@
<?php
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Tests\SolrIndexSubsitesTest\SolrIndexSubsitesTest_Index;
@ -10,7 +12,8 @@ if (class_exists('\Phockito')) {
/**
* Subsite specific solr testing
*/
class SolrIndexSubsitesTest extends SapphireTest {
class SolrIndexSubsitesTest extends SapphireTest
{
// @todo
// protected static $fixture_file = 'SolrIndexSubsitesTest/SolrIndexSubsitesTest.yml';
@ -127,10 +130,10 @@ class SolrIndexSubsitesTest extends SapphireTest {
));
\Phockito::verify($serviceMock)->addDocument($doc1);
\Phockito::verify($serviceMock)->addDocument($doc2);
}
public function testCorrectSubsiteIDOnPageWrite() {
public function testCorrectSubsiteIDOnPageWrite()
{
$mockWrites = array(
'3367:SiteTree:a:1:{s:22:"SearchVariantVersioned";s:4:"Live";}' => array(
'base' => 'SiteTree',
@ -187,7 +190,8 @@ class SolrIndexSubsitesTest extends SapphireTest {
}
}
public function testCorrectSubsiteIDOnFileWrite() {
public function testCorrectSubsiteIDOnFileWrite()
{
$subsiteIDs = array('0') + $this->allFixtureIDs('Subsite');
$mockWrites = array(
'35910:File:a:0:{}' => array(
@ -238,5 +242,4 @@ class SolrIndexSubsitesTest extends SapphireTest {
$this->assertEquals($subsite->ID, $statefulIDs['state']['SearchVariantSubsites']);
}
}
}

View File

@ -1,5 +1,8 @@
<?php
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;
use SilverStripe\Dev\SapphireTest;
@ -8,14 +11,13 @@ use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_AmbiguousRelat
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_FakeIndex;
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_FakeIndex2;
use SilverStripe\FullTextSearch\Tests\SolrIndexTest\SolrIndexTest_BoostedIndex;
use SilverStripe\FullTextSearch\Solr\Services\Solr3Service;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_Container;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_HasOne;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_HasMany;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_ManyMany;
use SilverStripe\FullTextSearch\Tests\SearchUpdaterTest\SearchUpdaterTest_OtherContainer;
use SilverStripe\Core\Config\Config;
use SilverStripe\FullTextSearch\Search\Queries\SearchQuery;
use SilverStripe\FullTextSearch\Solr\Services\Solr3Service;
class SolrIndexTest extends SapphireTest
{
@ -181,7 +183,8 @@ class SolrIndexTest extends SapphireTest
$serviceMock->expects($this->exactly(2))
->method('search')
->withConsecutive([
->withConsecutive(
[
$this->equalTo('+(Field1:term^1.5 OR HasOneObject_Field1:term^3)'),
$this->anything(),
$this->anything(),

View File

@ -1,5 +1,7 @@
<?php
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataObject;

View File

@ -9,7 +9,8 @@ use SilverStripe\Versioned\Versioned;
/**
* Non-sitetree versioned dataobject
*/
class SolrIndexVersionedTest_Object extends DataObject implements TestOnly {
class SolrIndexVersionedTest_Object extends DataObject implements TestOnly
{
private static $table_name = 'SolrIndexVersionedTest_Object';

View File

@ -1,5 +1,7 @@
<?php
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;

View File

@ -1,5 +1,7 @@
<?php
namespace SilverStripe\FullTextSearch\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\FullTextSearch;
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;

View File

@ -20,7 +20,7 @@ class SolrReindexTest_ItemExtension extends DataExtension implements TestOnly
* @param SQLSelect $query
* @param DataQuery $dataQuery
*/
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = NULL)
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
{
$variant = SolrReindexTest_Variant::get_current();
if ($variant !== null && !$query->filtersOnID()) {

View File

@ -12,7 +12,13 @@ use SilverStripe\FullTextSearch\Solr\SolrIndex;
class SolrReindexTest_TestHandler extends SolrReindexBase
{
public function processGroup(
LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group,
$taskName
) {
$indexName = $indexInstance->getIndexName();
$stateName = json_encode($state);