Skip to content

Commit 6e260db

Browse files
authored
Merge pull request #2 from nswdpc/dev-stan-modules
Added static analyse modules + CI files
2 parents b65abdd + daa3ba0 commit 6e260db

File tree

8 files changed

+106
-49
lines changed

8 files changed

+106
-49
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: CI
2+
3+
on:
4+
pull_request: null
5+
6+
jobs:
7+
Silverstripe:
8+
name: 'Silverstripe (bundle)'
9+
uses: nswdpc/ci-files/.github/workflows/silverstripe_53_83.yml@v-4
10+
PHPStan:
11+
name: 'PHPStan (analyse)'
12+
uses: nswdpc/ci-files/.github/workflows/phpstan.silverstripe_83.yml@v-4
13+
needs: Silverstripe

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/vendor/
33
.DS_Store
44
/.php-cs-fixer.cache
5+
/public/
6+
/composer.lock

.php-cs-fixer.dist.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

composer.json

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,69 @@
1414
"role": "Developer"
1515
}
1616
],
17+
"repositories": [
18+
{
19+
"type": "vcs",
20+
"url": "https://codeberg.org/codemdev/silverstripe-typesense.git"
21+
}
22+
],
1723
"support": {
18-
"key" : "value"
24+
"key": "value"
1925
},
2026
"require": {
2127
"nswdpc/waratah": "^2",
22-
"nswdpc/silverstripe-typesense-elemental": "^0.2",
28+
"nswdpc/silverstripe-typesense-elemental": "dev-dev-stan-modules as 0.2.9999",
2329
"silverstripe/asset-admin": "*",
2430
"silverstripe/linkfield": "*",
2531
"silverstripe/framework": "^5",
2632
"silverstripe/tagfield": "*"
2733
},
2834
"require-dev": {
2935
"phpunit/phpunit": "^9.5",
30-
"friendsofphp/php-cs-fixer": "^3"
36+
"cambis/silverstan": "^2",
37+
"cambis/silverstripe-rector": "^2",
38+
"friendsofphp/php-cs-fixer": "^3",
39+
"nswdpc/ci-files": "dev-v-4",
40+
"phpstan/phpstan": "^2",
41+
"rector/rector": "^2"
3142
},
3243
"autoload": {
3344
"psr-4": {
3445
"NSWDPC\\Waratah\\Typesense\\": [
3546
"src/"
3647
]
3748
}
38-
}
49+
},
50+
"scripts": {
51+
"phpstan-analyse": "./vendor/bin/phpstan analyse --ansi --no-progress --no-interaction --configuration vendor/nswdpc/ci-files/phpstan/.phpstan.silverstripe.neon src/",
52+
"rector-dryrun": "./vendor/bin/rector process --dry-run --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/*.php",
53+
"rector-process": "./vendor/bin/rector process --no-diffs --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/*.php",
54+
"phpcsfixer-fix": "./vendor/bin/php-cs-fixer fix --ansi --no-interaction --config vendor/nswdpc/ci-files/php-cs-fixer/.php-cs-fixer.php src/"
55+
},
56+
"config": {
57+
"allow-plugins": {
58+
"composer/installers": true,
59+
"silverstripe/recipe-plugin": true,
60+
"php-http/discovery": true,
61+
"silverstripe/vendor-plugin": true,
62+
"phpstan/extension-installer": true
63+
}
64+
},
65+
"extra": {
66+
"project-files-installed": [
67+
".htaccess",
68+
"app/.htaccess",
69+
"app/_config/mimevalidator.yml",
70+
"app/_config/mysite.yml",
71+
"app/src/Page.php",
72+
"app/src/PageController.php"
73+
],
74+
"public-files-installed": [
75+
".htaccess",
76+
"index.php",
77+
"web.config"
78+
]
79+
},
80+
"minimum-stability": "dev",
81+
"prefer-stable": true
3982
}

src/Extensions/SiteTreeExtension.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
/**
88
* Waratah smarts for the advanced search form
9+
* @extends \SilverStripe\Core\Extension<(\SilverStripe\CMS\Model\SiteTree & static)>
910
*/
10-
class SiteTreeExtension extends Extension {
11-
11+
class SiteTreeExtension extends Extension
12+
{
1213
/**
1314
* Provide specific updates to the search result data
1415
*/
15-
public function afterGetTypesenseSearchResult(array &$data): void {
16+
public function afterGetTypesenseSearchResult(array &$data): void
17+
{
1618
$owner = $this->getOwner();
17-
if($lastupdated = $owner->PageLastUpdated()) {
19+
if (($owner instanceof \Page) && ($lastUpdated = $owner->PageLastUpdated())) {
1820
$data['Date'] = $lastUpdated->Human;
1921
}
2022
}

src/Forms/AdvancedSearchForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
/**
99
* Waratah smarts for the advanced search form
1010
*/
11-
class AdvancedSearchForm extends BaseAdvancedSearchForm {
12-
11+
class AdvancedSearchForm extends BaseAdvancedSearchForm
12+
{
1313
use FilterFormTrait;
1414

1515
}

src/Models/Configuration.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
/**
1212
* Provides configuration for search forms and global search forms
1313
*/
14-
class Configuration implements TemplateGlobalProvider {
15-
14+
class Configuration implements TemplateGlobalProvider
15+
{
1616
use Configurable;
1717

1818
/**
1919
* Provide a global search form
2020
*/
21-
public static function get_global_search_form(): ?SearchForm {
22-
$form = null;
23-
if($searchPage = TypesenseSearchPage::get()->filter(['IsGlobalSearch' => 1])->first()) {
21+
public static function get_global_search_form(): ?SearchForm
22+
{
23+
if ($searchPage = TypesenseSearchPage::get()->filter(['IsGlobalSearch' => 1])->first()) {
2424
$controller = TypesenseSearchPageController::create($searchPage);
25+
// @phpstan-ignore return.type
2526
return SearchForm::create(
2627
$controller,
2728
'GlobalSearchForm'

src/Models/Elements/HeroSearch.php

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
use NSWDPC\Typesense\Elemental\Models\Elements\TypesenseSearchElement;
66
use SilverStripe\AssetAdmin\Forms\UploadField;
77
use SilverStripe\Assets\Image;
8-
use SilverStripe\Forms\ListboxField;
98
use SilverStripe\Forms\TextField;
109
use SilverStripe\LinkField\Form\MultiLinkField;
1110
use SilverStripe\LinkField\Models\Link;
1211
use SilverStripe\ORM\ArrayList;
1312
use SilverStripe\View\ArrayData;
1413

15-
1614
/**
1715
* Provides a hero search element conforming to the NSW Design System Hero Search Component
16+
* @property string $Title
17+
* @property ?string $Subtitle
18+
* @property ?string $SuggestedTerms
19+
* @property int $BackgroundImageID
20+
* @method \SilverStripe\Assets\Image BackgroundImage()
21+
* @method \SilverStripe\ORM\HasManyList<\SilverStripe\LinkField\Models\Link> Links()
1822
*/
19-
class HeroSearch extends TypesenseSearchElement {
20-
23+
class HeroSearch extends TypesenseSearchElement
24+
{
2125
private static string $icon = 'font-icon-search';
2226

2327
private static string $table_name = 'TypesenseHeroSearch';
@@ -56,14 +60,18 @@ class HeroSearch extends TypesenseSearchElement {
5660
/**
5761
* @inheritdoc
5862
*/
59-
public function getType() {
63+
#[\Override]
64+
public function getType()
65+
{
6066
return _t(static::class . '.BlockType', $this->i18n_singular_name());
6167
}
6268

6369
/**
6470
* Update CMS fields
6571
*/
66-
public function getCmsFields() {
72+
#[\Override]
73+
public function getCmsFields()
74+
{
6775
$fields = parent::getCmsFields();
6876
$fields->removeByName(['Links']);
6977
$fields->addFieldsToTab(
@@ -100,19 +108,22 @@ public function getCmsFields() {
100108
return $fields;
101109
}
102110

103-
public function getSuggestedTermsAsArray(): array {
111+
public function getSuggestedTermsAsArray(): array
112+
{
104113
$list = explode(",", $this->SuggestedTerms ?? '');
105-
return array_filter(array_values($list));
114+
return array_filter($list);
106115
}
107116

108-
public function getLinkedSuggestedTerms(): ArrayList {
117+
public function getLinkedSuggestedTerms(): ArrayList
118+
{
109119
$list = ArrayList::create();
110120
$page = $this->SearchPage();
111-
if(!$page || !$page->isInDB()) {
121+
if (!$page || !$page->isInDB()) {
112122
return $list;
113123
}
124+
114125
$terms = $this->getSuggestedTermsAsArray();
115-
foreach($terms as $term) {
126+
foreach ($terms as $term) {
116127
$term = strip_tags(trim((string) $term));
117128
$list->push(
118129
ArrayData::create([
@@ -121,25 +132,31 @@ public function getLinkedSuggestedTerms(): ArrayList {
121132
])
122133
);
123134
}
135+
124136
return $list;
125137
}
126138

127139
/**
128140
* Render element into template
129141
*/
130-
public function forTemplate($holder = true) {
142+
#[\Override]
143+
public function forTemplate($holder = true)
144+
{
131145
$templates = $this->getRenderTemplates();
146+
/** @var \NSWDPC\Typesense\Elemental\Controllers\TypesenseSearchElementController $controller */
147+
$controller = $this->getController();
132148
$templateData = ArrayData::create([
133149
'Title' => $this->Title,
134150
'Subtitle' => $this->Subtitle,
135-
'Form' => $this->getController()->SearchForm(),
151+
'Form' => $controller->SearchForm(),
136152
'Image' => $this->BackgroundImage(),
137153
'Links' => $this->Links(),
138154
'Terms' => $this->getLinkedSuggestedTerms()
139155
]);
140156
if ($templates) {
141157
return $this->customise($templateData)->renderWith($templates);
142158
}
159+
143160
return null;
144161
}
145162

0 commit comments

Comments
 (0)