Changeset 2579590
- Timestamp:
- 08/07/2021 02:35:29 AM (5 years ago)
- Location:
- wp-github-card/trunk
- Files:
-
- 6 edited
-
readme.txt (modified) (2 diffs)
-
src/Renderer.php (modified) (5 diffs)
-
src/Repos.php (modified) (2 diffs)
-
src/Service.php (modified) (5 diffs)
-
src/Shortcode.php (modified) (5 diffs)
-
src/User.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-github-card/trunk/readme.txt
r2327975 r2579590 4 4 Tags: github, shortcode 5 5 Requires at least: 4.9.6 6 Tested up to: 5. 4.27 Requires PHP: 7. 3+8 Stable tag: 2. 0.06 Tested up to: 5.8 7 Requires PHP: 7.4+ 8 Stable tag: 2.1.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 37 37 == Changelog == 38 38 39 = 2.1.0 = 40 * required php7.4 or later, added typed properties 39 41 = 2.0.0 = 40 42 * required php7.3 or later, end of support php5 -
wp-github-card/trunk/src/Renderer.php
r1889368 r2579590 6 6 * Class WP\GitHub\Renderer 7 7 * html renderer 8 * @package WP_GitHub_Card 8 * @package WP_GitHub_Card 9 9 * @since 1.0.0 10 10 * @link https://twig.symfony.com/ … … 13 13 14 14 /** @var \Twig_Environment */ 15 private $twig;15 private \Twig_Environment $twig; 16 16 /** @var string */ 17 private $base_dir;17 private string $base_dir; 18 18 19 19 public function __construct() { … … 32 32 * @param string $template_file 33 33 * @param array $params 34 * @return string 34 35 */ 35 public function render( $template_file, array $params ){36 public function render( string $template_file, array $params ): string { 36 37 $template = $this->twig->loadTemplate( $template_file ); 37 38 return $template->render( $params ); … … 41 42 * creates template cache directory 42 43 */ 43 public function prepare_template_cache() {44 $cache_dir = $this->base_dir . '/cache';44 public function prepare_template_cache(): void { 45 $cache_dir = $this->base_dir . '/cache'; 45 46 $this->twig->setCache( $cache_dir ); 46 47 } … … 50 51 * @global object $wp_filesystem 51 52 */ 52 public function delete_template_cache() {53 public function delete_template_cache(): void { 53 54 $this->twig->setCache( false ); 54 55 if( WP_Filesystem() ) { -
wp-github-card/trunk/src/Repos.php
r1889368 r2579590 11 11 final class Repos { 12 12 /** @var array */ 13 private $repos = [];13 private array $repos = []; 14 14 /** @var array */ 15 public $languages = [];15 public array $languages = []; 16 16 /** @var int */ 17 public $stargazers = 0;17 public int $stargazers = 0; 18 18 /** @var string */ 19 public $recently_active_repo = '';19 public string $recently_active_repo = ''; 20 20 21 21 public function __construct( array $data = null ) { … … 45 45 * @return int 46 46 */ 47 private function count_stargazers() {47 private function count_stargazers(): int { 48 48 return array_reduce( $this->repos, function($c, $i) { 49 49 return $c + $i['stargazers']; -
wp-github-card/trunk/src/Service.php
r1889368 r2579590 10 10 */ 11 11 final class Service { 12 const API_BASE_PATH = 'https://api.github.com';13 const CACHE_PREFIX = 'wp-github-card-';14 const CACHE_EXPIRED = 4*HOUR_IN_SECONDS;12 private const API_BASE_PATH = 'https://api.github.com'; 13 private const CACHE_PREFIX = 'wp-github-card-'; 14 private const CACHE_EXPIRED = 4*HOUR_IN_SECONDS; 15 15 16 16 /** @var string */ 17 private $user = null;17 private ?string $user = null; 18 18 /** @var string */ 19 private $token = null;19 private ?string $token = null; 20 20 21 public function __construct( $user = null,$token = null ) {21 public function __construct( ?string $user = null, ?string $token = null ) { 22 22 $this->user = $user; 23 23 $this->token = $token; … … 37 37 * @link https://developer.github.com/v3/users/#get-a-single-user 38 38 */ 39 public function get_user() {39 public function get_user(): User { 40 40 $url = self::API_BASE_PATH . '/users/' . $this->user; 41 41 $cache_key = self::CACHE_PREFIX . 'user-' . $this->user; … … 57 57 * @link https://developer.github.com/v3/repos/#list-user-repositories 58 58 */ 59 public function get_repos() {59 public function get_repos(): Repos { 60 60 $url = self::API_BASE_PATH . '/users/' . $this->user . '/repos?sort=pushed'; 61 61 $cache_key = self::CACHE_PREFIX . 'repos-' . $this->user; … … 76 76 * @global object $wpdb 77 77 */ 78 public function delete_transients() {78 public function delete_transients(): void { 79 79 global $wpdb; 80 80 $sql = "DELETE FROM `{$wpdb->prefix}options` WHERE `option_name` LIKE '_transient_wp-github-card-%'"; … … 89 89 * @link https://developer.github.com/v3/ 90 90 */ 91 private function request( $url ) {91 private function request( string $url ) { 92 92 $headers = [ 'Accept' => 'application/vnd.github.v3+json' ]; 93 93 if ( ! is_null( $this->token ) ) { -
wp-github-card/trunk/src/Shortcode.php
r1889368 r2579590 12 12 13 13 /** @var WP\GitHub\Renderer */ 14 private $renderer;14 private Renderer $renderer; 15 15 /** @var WP\GitHub\Service */ 16 private $service;16 private Service $service; 17 17 18 18 public function __construct() { … … 28 28 * @return string 29 29 */ 30 public function handler( array $atts ) {30 public function handler( array $atts ): string { 31 31 $defaults = [ 32 32 'user' => null, … … 46 46 * enqueues style sheet 47 47 */ 48 public function add_style() {48 public function add_style(): void { 49 49 wp_register_style( 50 50 'github-card-style', … … 57 57 * prepares template cache 58 58 */ 59 public function prepare_cache() {59 public function prepare_cache(): void { 60 60 $this->renderer->prepare_template_cache(); 61 61 } … … 64 64 * deletes transients and template cache 65 65 */ 66 public function delete_cache() {66 public function delete_cache(): void { 67 67 $this->service->delete_transients(); 68 68 $this->renderer->delete_template_cache(); -
wp-github-card/trunk/src/User.php
r1889368 r2579590 11 11 final class User { 12 12 /** @var string */ 13 public $login = '';13 public string $login = ''; 14 14 /** @var string */ 15 public $avatar = '';15 public string $avatar = ''; 16 16 /** @var string */ 17 public $name = '';17 public string $name = ''; 18 18 /** @var int */ 19 public $public_repos = 0;19 public int $public_repos = 0; 20 20 /** @var int */ 21 public $public_gists = 0;21 public int $public_gists = 0; 22 22 /** @var int */ 23 public $followers = 0;23 public int $followers = 0; 24 24 25 25 public function __construct( \stdClass $data = null ) { … … 43 43 * @return bool 44 44 */ 45 private function check_properties( \stdClass $data ) {45 private function check_properties( \stdClass $data ): bool { 46 46 $properties = [ 47 47 'login', 'avatar_url', 'name', 'public_repos', 'public_gists', 'followers'
Note: See TracChangeset
for help on using the changeset viewer.