diff --git a/.github/workflows/bedrock-php.yml b/.github/workflows/bedrock-php.yml index 7f18d9a..e94e5d4 100644 --- a/.github/workflows/bedrock-php.yml +++ b/.github/workflows/bedrock-php.yml @@ -7,9 +7,6 @@ on: concurrency: group: "${{ github.ref }}" cancel-in-progress: true -env: - TRAVIS_COMMIT: ${{ github.sha }} - TRAVIS_BRANCH: ${{ github.ref }} jobs: PHP_Phan: name: Phan @@ -42,7 +39,7 @@ jobs: PHP_Style: name: PHP Style runs-on: ubuntu-24.04 - timeout-minutes: 15 + timeout-minutes: 60 steps: - name: checkout # v4.1.0 @@ -64,5 +61,12 @@ jobs: - name: Setup Composer Cache uses: ./.github/actions/composite/setup-composer-cache + - name: Setup tmate session + # v3 + uses: mxschmitt/action-tmate@e5c7151931ca95bad1c6f4190c730ecf8c7dde48 + timeout-minutes: 60 + with: + limit-access-to-actor: true + - name: Test for Style run: "php ./ci/style.php" diff --git a/ci/phan.php b/ci/phan.php index ecf99f3..f162456 100755 --- a/ci/phan.php +++ b/ci/phan.php @@ -1,12 +1,12 @@ #!/usr/bin/env php analyze()) { exit(0); -} else { - exit(1); } +exit(1); diff --git a/ci/src/CommandLine.php b/ci/src/CommandLine.php index 3c2dfc6..1498378 100755 --- a/ci/src/CommandLine.php +++ b/ci/src/CommandLine.php @@ -14,10 +14,10 @@ class CommandLine */ protected function checkoutBranch($branch) { - Travis::fold("start", "git.checkout.".get_called_class()); + Travis::fold('start', 'git.checkout.'.get_called_class()); $this->call("git checkout $branch 2>&1"); $this->call('git fetch origin main:main 2>&1'); - Travis::fold("end", "git.checkout.".get_called_class()); + Travis::fold('end', 'git.checkout.'.get_called_class()); } /** diff --git a/ci/src/PHPStyler.php b/ci/src/PHPStyler.php index 7e29e17..bdb7466 100755 --- a/ci/src/PHPStyler.php +++ b/ci/src/PHPStyler.php @@ -8,12 +8,12 @@ class PHPStyler extends CommandLine { /** - * @var string Branch we are checking (usually coming from['TRAVIS_BRANCH']) + * @var string Branch we are checking (usually coming from['GITHUB_REF']) */ private $branch; /** - * @var string Commit we are checking (usually coming from['TRAVIS_COMMIT']) + * @var string Commit we are checking (usually coming from['GITHUB_SHA']) */ private $commit; @@ -39,7 +39,7 @@ public function check() $PHPLintCommand = "find . -name '*.php' -not \\( -path './externalLib/*' -or -path './vendor/*' -or -path './build/*' \\) -print0 | xargs -0 -L 1 -n 1 -P 8 php -l 1>/dev/null"; if ($this->branch === 'main') { - Travis::foldCall("lintmaster.php", $PHPLintCommand); + Travis::foldCall('lintmaster.php', $PHPLintCommand); echo 'Skipping style check for merge commits'; @@ -48,9 +48,9 @@ public function check() $this->checkoutBranch($this->branch); - Travis::foldCall("lint.php", $PHPLintCommand); + Travis::foldCall('lint.php', $PHPLintCommand); - Travis::fold("start", "style.php"); + Travis::fold('start', 'style.php'); Travis::timeStart(); echo 'Enforce PHP style'.PHP_EOL; $output = $this->getModifiedFiles($this->branch); @@ -83,13 +83,17 @@ public function check() } Travis::timeFinish(); - Travis::fold("end", "style.php"); + Travis::fold('end', 'style.php'); if (!$lintOK) { return false; } - Travis::foldCall("git.checkout2", "git checkout {$this->commit} 2>&1"); + echo 'post-checkout2'; + + Travis::foldCall('git.checkout2', 'git checkout {$this->commit} 2>&1'); + + echo 'post-checkout2'; return true; } diff --git a/ci/src/PhanAnalyzer.php b/ci/src/PhanAnalyzer.php index ec81446..ec3efea 100755 --- a/ci/src/PhanAnalyzer.php +++ b/ci/src/PhanAnalyzer.php @@ -8,7 +8,7 @@ class PhanAnalyzer extends CommandLine { /** - * @var string Branch we are checking (usually coming from['TRAVIS_BRANCH']) + * @var string Branch we are checking (usually coming from['GITHUB_REF']) */ private $branch; @@ -35,12 +35,12 @@ public function analyze() $this->checkoutBranch($this->branch); - Travis::fold("start", "phan.analyze"); + Travis::fold('start', 'phan.analyze'); Travis::timeStart(); echo 'Analyze PHP using Phan'.PHP_EOL; - $changedFiles = $this->eexec("git diff main...{$this->branch} --name-status | egrep \"^[A|M].*\\.php$\" | cut -f 2"); - echo "Analyzing files:".PHP_EOL; - $lintErrors = $this->eexec("./vendor/bin/phan -p -z --processes 5", false); + $changedFiles = $this->eexec('git diff main...{$this->branch} --name-status | egrep \"^[A|M].*\\.php$\" | cut -f 2'); + echo 'Analyzing files:'.PHP_EOL; + $lintErrors = $this->eexec('./vendor/bin/phan -p -z --processes 5', false); $lintOK = true; foreach ($lintErrors as $lintError) { foreach ($changedFiles as $file) { @@ -52,7 +52,7 @@ public function analyze() } } Travis::timeFinish(); - Travis::fold("end", "phan.analyze"); + Travis::fold('end', 'phan.analyze'); return $lintOK; } diff --git a/ci/src/Travis.php b/ci/src/Travis.php index 1eb0ae2..ea761ef 100644 --- a/ci/src/Travis.php +++ b/ci/src/Travis.php @@ -7,7 +7,7 @@ */ class Travis { - const ANSI_CLEAR = "\033[0K"; + public const ANSI_CLEAR = "\033[0K"; protected static $timerID; protected static $timerStart; @@ -19,7 +19,7 @@ public static function fold($action, $foldName) public static function foldCall($foldName, $cmd, $includeTimer = true) { - self::fold("start", $foldName); + self::fold('start', $foldName); if ($includeTimer) { self::timeStart(); @@ -31,7 +31,7 @@ public static function foldCall($foldName, $cmd, $includeTimer = true) self::timeFinish(); } - self::fold("end", $foldName); + self::fold('end', $foldName); if ($retVal !== 0) { exit($retVal); @@ -40,9 +40,9 @@ public static function foldCall($foldName, $cmd, $includeTimer = true) public static function timeStart() { - self::$timerID = sprintf("%08x", rand() * rand()); + self::$timerID = sprintf('%08x', rand() * rand()); self::$timerStart = self::getNanosecondsTime(); - echo "travis_time:start:".self::$timerID."\r".self::ANSI_CLEAR; + echo 'travis_time:start:'.self::$timerID."\r".self::ANSI_CLEAR; } public static function timeFinish() @@ -50,7 +50,7 @@ public static function timeFinish() $start = self::$timerStart; $end = self::getNanosecondsTime(); $duration = bcsub($end, $start); - echo "travis_time:end:".self::$timerID.":start=$start,finish=$end,duration=$duration\r".self::ANSI_CLEAR; + echo 'travis_time:end:'.self::$timerID.":start=$start,finish=$end,duration=$duration\r".self::ANSI_CLEAR; } public static function getNanosecondsTime() diff --git a/ci/style.php b/ci/style.php index 8498688..dd30078 100755 --- a/ci/style.php +++ b/ci/style.php @@ -5,6 +5,8 @@ require realpath(dirname(__FILE__)).'/../vendor/autoload.php'; use Expensify\Bedrock\CI\PHPStyler; -$styler = new PHPStyler($_SERVER['TRAVIS_BRANCH'], $_SERVER['TRAVIS_COMMIT']); +$styler = new PHPStyler($_SERVER['GITHUB_REF'], $_SERVER['GITHUB_SHA']); $valid = $styler->check(); +echo 'this should still work'; +echo $valid; exit((int) !$valid); diff --git a/composer.json b/composer.json index a2f8c63..6c18749 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "expensify/bedrock-php", "description": "Bedrock PHP Library", "type": "library", - "version": "2.2.2", + "version": "2.2.4", "authors": [ { "name": "Expensify", diff --git a/sample/SampleWorker.php b/sample/SampleWorker.php index 9a3716a..81bd765 100644 --- a/sample/SampleWorker.php +++ b/sample/SampleWorker.php @@ -1,4 +1,5 @@ client->getLogger()->info("BedrockCache read", [ + $this->client->getLogger()->info('BedrockCache read', [ 'key' => $name, 'version' => $version, ]); - $response = $this->call("ReadCache", ["name" => $fullName]); + $response = $this->call('ReadCache', ['name' => $fullName]); if ($response['code'] === 404) { throw new NotFound('The cache entry could not be found', 666); } @@ -41,10 +41,7 @@ public function read($name, $version = null) * Reads from the cache, but if it does not find the entry, it returns the passed default. * * @param string $name - * @param mixed $default * @param string $version - * - * @return mixed */ public function readWithDefault($name, $default, $version = null) { @@ -58,10 +55,6 @@ public function readWithDefault($name, $default, $version = null) /** * Gets data from a cache, if it is not present, it computes it by calling $computeFunction and saves the result in the cache. * - * @param string $name - * @param null|string $version - * @param callable $computeFunction - * * @return array */ public function get(string $name, ?string $version, callable $computeFunction) @@ -96,14 +89,14 @@ public function write($name, $value, $version = null, array $headers = []) // If we have a version, invalidate previous versions if ($version) { // Invalidate all other versions of this name before setting - $headers["invalidateName"] = "$name/*"; - $headers["name"] = "$name/$version"; + $headers['invalidateName'] = "$name/*"; + $headers['name'] = "$name/$version"; } else { // Just set this name - $headers["name"] = "$name/"; + $headers['name'] = "$name/"; } - $this->call("WriteCache", $headers, json_encode($value)); + $this->call('WriteCache', $headers, json_encode($value)); } /** diff --git a/src/Client.php b/src/Client.php index a9c5ea8..1725b38 100644 --- a/src/Client.php +++ b/src/Client.php @@ -607,14 +607,14 @@ private function sendRawRequest(string $host, int $port, string $rawRequest) * @param ?string $preferredHost If passed, it will prefer this host over any of the configured ones. This does not * ensure it will use that host, but it will try to use it if its not blacklisted. * - * @suppress PhanUndeclaredConstant - suppresses TRAVIS_RUNNING + * @suppress PhanUndeclaredConstant - suppresses ARE_GITHUB_ACTIONS_RUNNING */ private function getPossibleHosts(?string $preferredHost, bool $resetHosts = false) { // We get the host configs from the APC cache. Then, we check the configuration there with the passed // configuration and if it's outdated (ie: it has different hosts from the one in the config), we reset it. This // is so that we don't keep the old cache after changing the hosts or failover configuration. - if (!defined('TRAVIS_RUNNING') || !TRAVIS_RUNNING) { + if (!defined('ARE_GITHUB_ACTIONS_RUNNING') || !ARE_GITHUB_ACTIONS_RUNNING) { $apcuKey = self::APCU_CACHE_PREFIX.$this->clusterName; if ($resetHosts) { $this->logger->info('Bedrock\Client - Resetting host configs'); @@ -838,12 +838,12 @@ private static function toUTF8($str) * configuration. * We also close and clear the socket from the cache, so we don't reuse it. * - * @suppress PhanUndeclaredConstant - suppresses TRAVIS_RUNNING + * @suppress PhanUndeclaredConstant - suppresses ARE_GITHUB_ACTIONS_RUNNING */ private function markHostAsFailed(string $host) { $blacklistedUntil = time() + rand(1, $this->maxBlackListTimeout); - if (!defined('TRAVIS_RUNNING') || !TRAVIS_RUNNING) { + if (!defined('ARE_GITHUB_ACTIONS_RUNNING') || !ARE_GITHUB_ACTIONS_RUNNING) { $apcuKey = self::APCU_CACHE_PREFIX.$this->clusterName; $hostConfigs = apcu_fetch($apcuKey); $hostConfigs[$host]['blacklistedUntil'] = $blacklistedUntil; diff --git a/src/DB.php b/src/DB.php index 033cb6a..e84bf44 100644 --- a/src/DB.php +++ b/src/DB.php @@ -17,14 +17,14 @@ class DB extends Plugin * * @var int */ - const CODE_OK = 200; + public const CODE_OK = 200; /** * Failed query response code. * * @var int */ - const CODE_QUERY_FAILED = 502; + public const CODE_QUERY_FAILED = 502; /** * Executes a single SQL query. @@ -52,7 +52,7 @@ public function query($sql): Response */ public function run(string $sql, bool $idempotent, int $timeout = 60000): Response { - $sql = substr($sql, -1) === ";" ? $sql : $sql.";"; + $sql = substr($sql, -1) === ';' ? $sql : $sql.';'; $matches = []; preg_match('/\s*(select|insert|delete|update).*/i', $sql, $matches); $operation = isset($matches[1]) && in_array(strtolower($matches[1]), ['insert', 'update', 'delete', 'select']) ? strtolower($matches[1]) : 'unknown'; @@ -61,7 +61,7 @@ public function run(string $sql, bool $idempotent, int $timeout = 60000): Respon 'Query', [ 'query' => $sql, - 'format' => "json", + 'format' => 'json', 'idempotent' => $idempotent, 'timeout' => $timeout, ] @@ -69,7 +69,7 @@ public function run(string $sql, bool $idempotent, int $timeout = 60000): Respon }); if ($response->getCode() === self::CODE_QUERY_FAILED) { - throw new BedrockError($response->getCodeLine()." - ".$response->getError(), $response->getCode()); + throw new BedrockError($response->getCodeLine().' - '.$response->getError(), $response->getCode()); } if ($response->getCode() !== self::CODE_OK) { diff --git a/src/DB/Response.php b/src/DB/Response.php index 8ec6e14..aa0f9d8 100644 --- a/src/DB/Response.php +++ b/src/DB/Response.php @@ -10,7 +10,7 @@ */ class Response implements JsonSerializable, Countable { - protected $container = null; + protected $container; public function __construct(array $leValue) { @@ -47,9 +47,6 @@ public function jsonSerialize(): array * Shortcut method to access the value inside the container. * * @param string|array $index - * @param mixed $default - * - * @return mixed */ protected function getFromContainer($index, $default = null) { @@ -80,9 +77,6 @@ protected function getFromContainer($index, $default = null) * Shortcut function to set data inside the container. * * @param string|int|array $index - * @param mixed $value - * - * @return mixed */ protected function setContainerValue($index, $value) { diff --git a/src/Exceptions/BedrockError.php b/src/Exceptions/BedrockError.php index 7ef167f..53d0e53 100644 --- a/src/Exceptions/BedrockError.php +++ b/src/Exceptions/BedrockError.php @@ -6,7 +6,7 @@ class BedrockError extends Exception { - public function __construct($message, $code = 666, Exception $previous = null) + public function __construct($message, $code = 666, ?Exception $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Exceptions/Jobs/RetryableException.php b/src/Exceptions/Jobs/RetryableException.php index 5d2455e..2537d6a 100644 --- a/src/Exceptions/Jobs/RetryableException.php +++ b/src/Exceptions/Jobs/RetryableException.php @@ -34,16 +34,15 @@ class RetryableException extends BedrockError /** * RetryableException constructor. * - * @param string $message Message of the exception - * @param int $delay Time to delay the retry (in seconds; maximum value is currently 999) - * @param ?int $code Code of the exception - * @param ?Exception $previous - * @param string $name New name for the job - * @param string $nextRun When to retry the job (takes precedence over delay; expects format Y-m-d H:i:s) - * @param bool $ignoreRepeat When calculating when to retry the job, should we ignore the repeat parameter and - * use $delay or $nextRun instead + * @param string $message Message of the exception + * @param int $delay Time to delay the retry (in seconds; maximum value is currently 999) + * @param ?int $code Code of the exception + * @param string $name New name for the job + * @param string $nextRun When to retry the job (takes precedence over delay; expects format Y-m-d H:i:s) + * @param bool $ignoreRepeat When calculating when to retry the job, should we ignore the repeat parameter and + * use $delay or $nextRun instead */ - public function __construct(string $message, int $delay = 0, int $code = null, Exception $previous = null, string $name = '', string $nextRun = '', bool $ignoreRepeat = false) + public function __construct(string $message, int $delay = 0, ?int $code = null, ?Exception $previous = null, string $name = '', string $nextRun = '', bool $ignoreRepeat = false) { $code = $code ?? 666; $this->delay = $delay; diff --git a/src/Jobs.php b/src/Jobs.php index c69b7b9..1deb65a 100644 --- a/src/Jobs.php +++ b/src/Jobs.php @@ -122,13 +122,13 @@ class Jobs extends Plugin * @param array $headers Headers to send * @param string $body Body of the request * + * @return array + * * @throws DoesNotExist * @throws IllegalAction * @throws MalformedAttribute * @throws SqlFailed * @throws GenericError - * - * @return array */ public function call($method, $headers = [], $body = '') { @@ -390,7 +390,7 @@ public function failJob($jobID) /** * Retry a job. Job must be in a RUNNING state to be able to be retried. */ - public function retryJob(int $jobID, int $delay = 0, array $data = null, string $name = '', string $nextRun = '', ?int $priority = null, bool $ignoreRepeat = false): array + public function retryJob(int $jobID, int $delay = 0, ?array $data = null, string $name = '', string $nextRun = '', ?int $priority = null, bool $ignoreRepeat = false): array { return $this->call( 'RetryJob', diff --git a/src/Plugin.php b/src/Plugin.php index b5ca4fc..1fa158c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -16,8 +16,6 @@ class Plugin /** * Constructor. - * - * @param Client $client */ public function __construct(Client $client) { diff --git a/src/Status.php b/src/Status.php index 3d6993c..96c4c95 100644 --- a/src/Status.php +++ b/src/Status.php @@ -14,6 +14,6 @@ class Status extends Plugin */ public function ping() { - return $this->client->call("Ping"); + return $this->client->call('Ping'); } }