diff --git a/src/Rule.php b/src/Rule.php index 53c3f80..66d5abb 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -31,6 +31,7 @@ protected static function ensureHttpClientIsLoaded(): TwitterClient public static function all(): array { $rules = static::ensureHttpClientIsLoaded()->request('GET', 'https://api.twitter.com/2/tweets/search/stream/rules'); + return array_map(static function ($rawRule) { $rule = new self($rawRule['value'], $rawRule['tag']); $rule->withId($rawRule['id']); diff --git a/src/RuleBuilder.php b/src/RuleBuilder.php index e89035c..1bb6306 100644 --- a/src/RuleBuilder.php +++ b/src/RuleBuilder.php @@ -374,6 +374,7 @@ public function raw(string $expression): static public function save(string $tag = null): Rule { $compiled = $this->compile(); + return Rule::create($compiled, $tag ?? $compiled); } } diff --git a/src/TwitterStream.php b/src/TwitterStream.php index b4e4fab..813b872 100644 --- a/src/TwitterStream.php +++ b/src/TwitterStream.php @@ -39,7 +39,7 @@ public function filteredTweets(Sets $sets = null): Generator }; while ($shouldKeepListening()) { - $char = $this->streamConnection->read(1) ; + $char = $this->streamConnection->read(1); $tweet = $char; while ($char !== "\n" && $tweet[-1] !== "\r") { @@ -67,11 +67,10 @@ protected function connectToFilteredStream(Sets $sets = null): StreamInterface public function __destruct() { - // If the connection was never initialized, this throws an error. + // If the connection was never initialized, this throws an error. try { - $this->stopListening(); + $this->stopListening(); } catch (Error) { - } }