Skip to content

Commit 0a85fb6

Browse files
robertbossaertSimonvanWijhe
authored andcommitted
(chore): format and add function checker to DependencyChecker.php
1 parent 30e2787 commit 0a85fb6

File tree

9 files changed

+80
-67
lines changed

9 files changed

+80
-67
lines changed

config/seopress_api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
'_seopress_social_twitter_img_width',
1818
'_seopress_social_twitter_img_height',
1919
]
20-
];
20+
];

src/Base/Admin/AdminServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function filterPostLink(string $link, WP_Post $post, bool $leavename, $sa
3333
*/
3434
public function filterPreviewLink(string $link, WP_Post $post): string
3535
{
36-
if ($post->post_type !== 'openpub-item' || ! $this->plugin->settings->isPortalSlugValid()) {
36+
if ($post->post_type !== 'openpub-item' || ! $this->plugin->settings->isPortalSlugValid()) {
3737
return $link;
3838
}
3939

src/Base/Foundation/DependencyChecker.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function failed(): bool
4242
case 'plugin':
4343
$this->checkPlugin($dependency);
4444
break;
45+
case 'function':
46+
$this->checkFunction($dependency);
47+
break;
4548
}
4649
}
4750

@@ -116,14 +119,25 @@ private function checkPlugin(array $dependency): void
116119
}
117120
}
118121

122+
/**
123+
* Checks if required function exists.
124+
*/
125+
private function checkFunction(array $dependency): void
126+
{
127+
if (! function_exists($dependency['name'])) {
128+
$this->markFailed($dependency, __('Function does not exist:', 'openpub-base') . ' <b>' . $dependency['name'] . '</b>');
129+
}
130+
}
131+
132+
119133
/**
120134
* Checks the installed version of the plugin.
121135
*/
122136
private function checkVersion(array $dependency): bool
123137
{
124138
try {
125139
$file = file_get_contents(WP_PLUGIN_DIR . '/' . $dependency['file']);
126-
} catch(\Exception $e) {
140+
} catch (\Exception $e) {
127141
return false;
128142
}
129143

src/Base/Metabox/Commands/AbstractConvert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function execute(): void
3131
foreach ($this->flattenArray($holder) as $item) {
3232
try {
3333
$this->convert($item);
34-
} catch(Exception $e) {
34+
} catch (Exception $e) {
3535
WP_CLI::error(sprintf('Something went wrong with converting item [%s]. Error: %s', $item->post_title, $e->getMessage()));
3636
}
3737
}

src/Base/Metabox/Commands/ConvertExpirationDate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function convertDateToTimeStamp(WP_Post $item): ?int
3131

3232
try {
3333
$object = new DateTime($date);
34-
} catch(Exception $e) {
34+
} catch (Exception $e) {
3535
return null;
3636
}
3737

src/Base/PostType/PostTypeServiceProvider.php

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,69 @@
77

88
class PostTypeServiceProvider extends ServiceProvider
99
{
10-
/**
11-
* The array of posttype definitions from the config
12-
*/
13-
protected array $configPostTypes = [];
10+
/**
11+
* The array of posttype definitions from the config
12+
*/
13+
protected array $configPostTypes = [];
1414

15-
public function register()
16-
{
17-
$this->plugin->loader->addAction('init', $this, 'registerPostTypes');
18-
$this->plugin->loader->addAction('pre_get_posts', $this, 'orderByPublishedDate');
19-
$this->plugin->loader->addAction('wp_insert_post_data', $this, 'fillPostName', 10, 4);
20-
}
15+
public function register()
16+
{
17+
$this->plugin->loader->addAction('init', $this, 'registerPostTypes');
18+
$this->plugin->loader->addAction('pre_get_posts', $this, 'orderByPublishedDate');
19+
$this->plugin->loader->addAction('wp_insert_post_data', $this, 'fillPostName', 10, 4);
20+
}
2121

22-
/**
23-
* Add default order.
24-
*/
25-
public function orderByPublishedDate(WP_Query $query): void
26-
{
27-
if (! is_admin()) {
28-
return;
29-
}
22+
/**
23+
* Add default order.
24+
*/
25+
public function orderByPublishedDate(WP_Query $query): void
26+
{
27+
if (! is_admin()) {
28+
return;
29+
}
3030

31-
if (! $query->is_main_query() || 'openpub-item' != $query->get('post_type')) {
32-
return;
33-
}
31+
if (! $query->is_main_query() || 'openpub-item' != $query->get('post_type')) {
32+
return;
33+
}
3434

35-
if (isset($_GET['orderby'])) {
36-
return;
37-
}
35+
if (isset($_GET['orderby'])) {
36+
return;
37+
}
3838

39-
$query->set('orderby', 'post_date');
40-
$query->set('order', 'DESC');
41-
}
39+
$query->set('orderby', 'post_date');
40+
$query->set('order', 'DESC');
41+
}
4242

43-
/**
44-
* Register custom posttypes.
45-
*/
46-
public function registerPostTypes(): void
47-
{
48-
if (function_exists('register_extended_post_type')) {
49-
$this->configPostTypes = apply_filters('owc/openpub-base/before-register-posttypes', $this->plugin->config->get('posttypes'));
50-
foreach ($this->configPostTypes as $postTypeName => $postType) {
51-
// Examples of registering post types: http://johnbillion.com/extended-cpts/
52-
register_extended_post_type($postTypeName, $postType['args'], $postType['names']);
53-
}
54-
}
55-
}
43+
/**
44+
* Register custom posttypes.
45+
*/
46+
public function registerPostTypes(): void
47+
{
48+
if (function_exists('register_extended_post_type')) {
49+
$this->configPostTypes = apply_filters('owc/openpub-base/before-register-posttypes', $this->plugin->config->get('posttypes'));
50+
foreach ($this->configPostTypes as $postTypeName => $postType) {
51+
// Examples of registering post types: http://johnbillion.com/extended-cpts/
52+
register_extended_post_type($postTypeName, $postType['args'], $postType['names']);
53+
}
54+
}
55+
}
5656

57-
/**
58-
* Always fill the post_name when empty and a post is not published.
59-
* When previewing an openpub-item the post_name needs to be present, which is set by default when the post is published.
60-
*/
61-
public function fillPostName(array $post, array $postarr, array $unsanitizedPostarr, bool $update): array
62-
{
63-
if ('openpub-item' !== $post['post_type'] || empty($postarr['ID']) || 'publish' === $post['post_status']) {
64-
return $post;
65-
}
57+
/**
58+
* Always fill the post_name when empty and a post is not published.
59+
* When previewing an openpub-item the post_name needs to be present, which is set by default when the post is published.
60+
*/
61+
public function fillPostName(array $post, array $postarr, array $unsanitizedPostarr, bool $update): array
62+
{
63+
if ('openpub-item' !== $post['post_type'] || empty($postarr['ID']) || 'publish' === $post['post_status']) {
64+
return $post;
65+
}
6666

67-
if (! empty($postarr['post_name'])) {
68-
return $post;
69-
}
67+
if (! empty($postarr['post_name'])) {
68+
return $post;
69+
}
7070

71-
$post['post_name'] = \sanitize_title($post['post_title']);
71+
$post['post_name'] = \sanitize_title($post['post_title']);
7272

73-
return $post;
74-
}
73+
return $post;
74+
}
7575
}

src/Base/RestAPI/Controllers/ThemeController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace OWC\OpenPub\Base\RestAPI\Controllers;
44

5-
use WP_Post;
5+
use OWC\OpenPub\Base\Repositories\Theme;
66
use WP_Error;
7+
use WP_Post;
78
use WP_REST_Request;
8-
use OWC\OpenPub\Base\Repositories\Theme;
99

1010
class ThemeController extends BaseController
1111
{

src/Base/Settings/SettingsServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function register()
1717

1818
public function registerMissingNumberField($field, $escapedValue, $objectID, $objectType, $fieldTypeObject): void
1919
{
20-
echo $fieldTypeObject->input(array( 'type' => 'number' ));
20+
echo $fieldTypeObject->input([ 'type' => 'number' ]);
2121
}
2222

2323
public function registerSettingsPages(): void

tests/Unit/Base/RestAPI/Controllers/ItemControllerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use OWC\OpenPub\Base\Foundation\Loader;
88
use OWC\OpenPub\Base\Foundation\Plugin;
99
use OWC\OpenPub\Base\RestAPI\Controllers\ItemController;
10-
use OWC\OpenPub\Base\RestAPI\ItemFields\FeaturedImageField;
1110
use OWC\OpenPub\Tests\TestCase;
1211
use WP_Mock;
1312
use WP_Post;
@@ -44,9 +43,9 @@ public function it_transforms_a_wp_object_to_array()
4443
$post->post_date = '01-01-2021';
4544
$post->post_name = 'test-test';
4645

47-
$itemController = m::mock(ItemController::class)->makePartial();
46+
$itemController = m::mock(ItemController::class)->makePartial();
4847

49-
$itemController->shouldReceive('getImageUrl')->andReturn([]);
48+
$itemController->shouldReceive('getImageUrl')->andReturn([]);
5049

5150
WP_Mock::userFunction('get_the_post_thumbnail_url', [
5251
'args' => [
@@ -63,7 +62,7 @@ public function it_transforms_a_wp_object_to_array()
6362
'excerpt' => 'Test excerpt',
6463
'date' => '01-01-2021',
6564
'thumbnail_url' => 'url-to-image',
66-
'image' => [],
65+
'image' => [],
6766
'slug' => 'test-test',
6867
];
6968

0 commit comments

Comments
 (0)