From 820afa2284eb603c286921a302d5b827a1b47b9e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 22:39:59 -0400 Subject: [PATCH] Replace global $a with BaseObject::getApp() --- include/text.php | 3 --- mod/admin.php | 2 -- src/Worker/CheckVersion.php | 8 ++++---- src/Worker/Cron.php | 8 +++++--- src/Worker/CronJobs.php | 2 +- src/Worker/DBUpdate.php | 8 +++++--- src/Worker/DiscoverPoCo.php | 5 ++--- src/Worker/Expire.php | 8 +++++--- src/Worker/ForkHook.php | 8 +++++--- src/Worker/Notifier.php | 8 +++++--- src/Worker/OnePoll.php | 11 +++++++---- src/Worker/PubSubPublish.php | 8 +++++--- src/Worker/Queue.php | 2 -- src/Worker/UpdateGContact.php | 2 -- tests/ApiTest.php | 17 +++++++---------- tests/src/Core/Cache/CacheTest.php | 3 --- tests/src/Core/Lock/LockTest.php | 4 ---- 17 files changed, 51 insertions(+), 56 deletions(-) diff --git a/include/text.php b/include/text.php index 679873b53..6aa0c9d2d 100644 --- a/include/text.php +++ b/include/text.php @@ -519,7 +519,6 @@ $LOGGER_LEVELS = []; * LOGGER_DATA * LOGGER_ALL * - * @global App $a * @global array $LOGGER_LEVELS * @param string $msg * @param int $level @@ -590,12 +589,10 @@ function logger($msg, $level = 0) { * LOGGER_DATA * LOGGER_ALL * - * @global App $a * @global array $LOGGER_LEVELS * @param string $msg * @param int $level */ - function dlogger($msg, $level = 0) { $a = get_app(); diff --git a/mod/admin.php b/mod/admin.php index c90eb3c5e..da5000713 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -944,8 +944,6 @@ function admin_page_site_post(App $a) function update_table($table_name, $fields, $old_url, $new_url) { - global $a; - $dbold = dbesc($old_url); $dbnew = dbesc($new_url); diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index a6056ccbc..e37e37a06 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -16,10 +16,10 @@ use Friendica\Util\Network; * Checking the upstream version is optional (opt-in) and can be done to either * the master or the develop branch in the repository. */ -class CheckVersion { - public static function execute() { - global $a; - +class CheckVersion +{ + public static function execute() + { logger('checkversion: start'); $checkurl = Config::get('system', 'check_new_version_url', 'none'); diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index e425c0350..a0dfda330 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -13,9 +13,11 @@ use dba; require_once 'include/dba.php'; -Class Cron { - public static function execute($parameter = '', $generation = 0) { - global $a; +class Cron +{ + public static function execute($parameter = '', $generation = 0) + { + $a = \Friendica\BaseObject::getApp(); // Poll contacts with specific parameters if (!empty($parameter)) { diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index 80839874d..8b9d3b9bc 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -24,7 +24,7 @@ class CronJobs { public static function execute($command = '') { - global $a; + $a = \Friendica\BaseObject::getApp(); // No parameter set? So return if ($command == '') { diff --git a/src/Worker/DBUpdate.php b/src/Worker/DBUpdate.php index 5f85c8ebe..ed8e409e9 100644 --- a/src/Worker/DBUpdate.php +++ b/src/Worker/DBUpdate.php @@ -7,9 +7,11 @@ namespace Friendica\Worker; use Friendica\Core\Config; -class DBUpdate { - public static function execute() { - $a = get_app(); +class DBUpdate +{ + public static function execute() + { + $a = \Friendica\BaseObject::getApp(); // We are deleting the latest dbupdate entry. // This is done to avoid endless loops because the update was interupted. diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index f0335bc8e..c77830d60 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -15,7 +15,8 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use dba; -class DiscoverPoCo { +class DiscoverPoCo +{ /// @todo Clean up this mess of a parameter hell and split it in several classes public static function execute($command = '', $param1 = '', $param2 = '', $param3 = '', $param4 = '') { @@ -276,8 +277,6 @@ class DiscoverPoCo { // It is not removed since I hope that there will be a successor. return false; - $a = get_app(); - $url = "http://gstools.org/api/users_search/".urlencode($search); $result = Network::curl($url); diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index 6cc333dd0..685fad49e 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -15,9 +15,11 @@ use dba; require_once 'include/dba.php'; -class Expire { - public static function execute($param = '', $hook_name = '') { - global $a; +class Expire +{ + public static function execute($param = '', $hook_name = '') + { + $a = \Friendica\BaseObject::getApp(); require_once 'include/items.php'; diff --git a/src/Worker/ForkHook.php b/src/Worker/ForkHook.php index 6c138bace..3654bdd3c 100644 --- a/src/Worker/ForkHook.php +++ b/src/Worker/ForkHook.php @@ -7,9 +7,11 @@ namespace Friendica\Worker; use Friendica\Core\Addon; -Class ForkHook { - public static function execute($name, $hook, $data) { - global $a; +Class ForkHook +{ + public static function execute($name, $hook, $data) + { + $a = \Friendica\BaseObject::getApp(); Addon::callSingleHook($a, $name, $hook, $data); } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 6c3717200..385892f99 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -48,9 +48,11 @@ require_once 'include/items.php'; * and ITEM_ID is the id of the item in the database that needs to be sent to others. */ -class Notifier { - public static function execute($cmd, $item_id) { - global $a; +class Notifier +{ + public static function execute($cmd, $item_id) + { + $a = \Friendica\BaseObject::getApp(); logger('notifier: invoked: '.$cmd.': '.$item_id, LOGGER_DEBUG); diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index eaef5f252..951a20b01 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -21,8 +21,9 @@ require_once 'include/dba.php'; class OnePoll { - public static function execute($contact_id = 0, $command = '') { - global $a; + public static function execute($contact_id = 0, $command = '') + { + $a = \Friendica\BaseObject::getApp(); require_once 'include/items.php'; @@ -634,7 +635,8 @@ class OnePoll return; } - private static function RemoveReply($subject) { + private static function RemoveReply($subject) + { while (in_array(strtolower(substr($subject, 0, 3)), ["re:", "aw:"])) { $subject = trim(substr($subject, 4)); } @@ -648,7 +650,8 @@ class OnePoll * @param array $contact The personal contact entry * @param array $fields The fields that are updated */ - private static function updateContact($contact, $fields) { + private static function updateContact($contact, $fields) + { dba::update('contact', $fields, ['id' => $contact['id']]); dba::update('contact', $fields, ['uid' => 0, 'nurl' => $contact['nurl']]); } diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index 0a60e5a59..b90fc11a4 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -15,7 +15,8 @@ use dba; require_once 'include/items.php'; -class PubSubPublish { +class PubSubPublish +{ public static function execute($pubsubpublish_id = 0) { if ($pubsubpublish_id == 0) { @@ -25,8 +26,9 @@ class PubSubPublish { self::publish($pubsubpublish_id); } - private static function publish($id) { - global $a; + private static function publish($id) + { + $a = \Friendica\BaseObject::getApp(); $subscriber = dba::selectFirst('push_subscriber', [], ['id' => $id]); if (!DBM::is_result($subscriber)) { diff --git a/src/Worker/Queue.php b/src/Worker/Queue.php index c8ba5795a..1ec409056 100644 --- a/src/Worker/Queue.php +++ b/src/Worker/Queue.php @@ -25,8 +25,6 @@ class Queue { public static function execute($queue_id = 0) { - global $a; - $cachekey_deadguy = 'queue_run:deadguy:'; $cachekey_server = 'queue_run:server:'; diff --git a/src/Worker/UpdateGContact.php b/src/Worker/UpdateGContact.php index 98a62818e..b943d966b 100644 --- a/src/Worker/UpdateGContact.php +++ b/src/Worker/UpdateGContact.php @@ -15,8 +15,6 @@ class UpdateGContact { public static function execute($contact_id) { - global $a; - logger('update_gcontact: start'); if (empty($contact_id)) { diff --git a/tests/ApiTest.php b/tests/ApiTest.php index c33ee6bfa..1854c996b 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -5,12 +5,11 @@ namespace Friendica\Test; -use Friendica\App; use Friendica\Core\Config; use Friendica\Core\PConfig; -use Friendica\Network\BadRequestException; +use Friendica\Core\Protocol; +use Friendica\Core\System; use Friendica\Network\HTTPException; -use Friendica\Render\FriendicaSmarty; /** * Tests for the API functions. @@ -26,12 +25,10 @@ class ApiTest extends DatabaseTest */ protected function setUp() { - global $a; parent::setUp(); // Reusable App object - $this->app = new App(__DIR__.'/../'); - $a = $this->app; + $this->app = \Friendica\BaseObject::getApp(); // User data that the test database is populated with $this->selfUser = [ @@ -2164,7 +2161,7 @@ class ApiTest extends DatabaseTest public function testApiFormatItemsEmbededImages() { $this->assertEquals( - 'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid', + 'text ' . System::baseUrl() . '/display/item_guid', api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo') ); } @@ -2338,7 +2335,7 @@ class ApiTest extends DatabaseTest 'body' => '', 'verb' => '', 'author-id' => 43, - 'author-network' => \Friendica\Core\Protocol::DFRN, + 'author-network' => Protocol::DFRN, 'author-link' => 'http://localhost/profile/othercontact', 'plink' => '', ] @@ -2361,7 +2358,7 @@ class ApiTest extends DatabaseTest 'body' => '', 'verb' => '', 'author-id' => 43, - 'author-network' => \Friendica\Core\Protocol::DFRN, + 'author-network' => Protocol::DFRN, 'author-link' => 'http://localhost/profile/othercontact', 'plink' => '', ] @@ -2635,7 +2632,7 @@ class ApiTest extends DatabaseTest $result = api_statusnet_config('json'); $this->assertEquals('localhost', $result['config']['site']['server']); $this->assertEquals('default', $result['config']['site']['theme']); - $this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']); + $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']); $this->assertTrue($result['config']['site']['fancy']); $this->assertEquals('en', $result['config']['site']['language']); $this->assertEquals('UTC', $result['config']['site']['timezone']); diff --git a/tests/src/Core/Cache/CacheTest.php b/tests/src/Core/Cache/CacheTest.php index a2724c12b..39dc56f30 100644 --- a/tests/src/Core/Cache/CacheTest.php +++ b/tests/src/Core/Cache/CacheTest.php @@ -2,7 +2,6 @@ namespace Friendica\Test\src\Core\Cache; -use Friendica\App; use Friendica\Core\Config; use Friendica\Test\DatabaseTest; use Friendica\Util\DateTimeFormat; @@ -18,13 +17,11 @@ abstract class CacheTest extends DatabaseTest protected function setUp() { - global $a; parent::setUp(); $this->instance = $this->getInstance(); // Reusable App object $this->app = \Friendica\BaseObject::getApp(); - $a = $this->app; // Default config Config::set('config', 'hostname', 'localhost'); diff --git a/tests/src/Core/Lock/LockTest.php b/tests/src/Core/Lock/LockTest.php index 5e4bebd45..79ee023bd 100644 --- a/tests/src/Core/Lock/LockTest.php +++ b/tests/src/Core/Lock/LockTest.php @@ -2,10 +2,8 @@ namespace Friendica\Test\src\Core\Lock; -use Friendica\App; use Friendica\Core\Config; use Friendica\Test\DatabaseTest; -use PHPUnit\Framework\TestCase; abstract class LockTest extends DatabaseTest { @@ -18,13 +16,11 @@ abstract class LockTest extends DatabaseTest protected function setUp() { - global $a; parent::setUp(); $this->instance = $this->getInstance(); // Reusable App object $this->app = \Friendica\BaseObject::getApp(); - $a = $this->app; // Default config Config::set('config', 'hostname', 'localhost');