Advertisement
Equidea

HeadDna.php

Nov 10th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Equine;
  4.  
  5. class HeadDna {
  6.    
  7.     public const HEAD_CONVEX = 'cvx';
  8.     public const HEAD_STRAIGHT = 'str';
  9.     public const HEAD_CONCAVE = 'ccv';
  10.    
  11.     protected array $lower = [
  12.         self::HEAD_STRAIGHT,
  13.         self::HEAD_STRAIGHT
  14.     ];
  15.    
  16.     protected array $middle = [
  17.         self::HEAD_STRAIGHT,
  18.         self::HEAD_STRAIGHT
  19.     ];
  20.    
  21.     protected array $higher = [
  22.         self::HEAD_STRAIGHT,
  23.         self::HEAD_STRAIGHT
  24.     ];
  25.    
  26.     public function getLower() : array {
  27.         return $this->lower;
  28.     }
  29.    
  30.     public function getMiddle() : array {
  31.         return $this->middle;
  32.     }
  33.    
  34.     public function getHigher() : array {
  35.         return $this->higher;
  36.     }
  37.    
  38.     private function getActiveGene(array $allele) : string
  39.     {
  40.         if (in_array(self::HEAD_CONVEX, $allele)) {
  41.             return self::HEAD_CONVEX;
  42.         }
  43.        
  44.         if (in_array(self::HEAD_STRAIGHT, $allele)) {
  45.             return self::HEAD_STRAIGHT;
  46.         }
  47.        
  48.         return self::HEAD_CONCAVE;
  49.     }
  50.    
  51.     public function getActiveGenes() : array
  52.     {
  53.         return [
  54.             'lower' => $this->getActiveGene($this->lower),
  55.             'middle' => $this->getActiveGene($this->middle),
  56.             'higher' => $this->getActiveGene($this->higher)
  57.         ];
  58.     }
  59.    
  60.     public function getActiveGeneOccurances() : array
  61.     {
  62.         $occurances = array_count_values($this->getActiveGenes());
  63.  
  64.         return [
  65.             self::HEAD_CONVEX => $occurances[self::HEAD_CONVEX] ?? 0,
  66.             self::HEAD_STRAIGHT => $occurances[self::HEAD_STRAIGHT] ?? 0,
  67.             self::HEAD_CONCAVE => $occurances[self::HEAD_CONCAVE] ?? 0
  68.         ];
  69.     }
  70.    
  71.     public function setAllAlleles(array $alleles) : void
  72.     {
  73.         $this->lower = $alleles['lower'];
  74.         $this->middle = $alleles['middle'];
  75.         $this->higher = $alleles['higher'];
  76.     }
  77.    
  78.     public function getAllAlleles() : array
  79.     {
  80.         return [
  81.             'lower' => $this->lower,
  82.             'middle' => $this->middle,
  83.             'higher' => $this->higher
  84.         ];
  85.     }
  86.    
  87.     public function importJson(array $jsonDna) : void
  88.     {
  89.         $this->lower = json_decode($jsonDna['lower']);
  90.         $this->middle = json_decode($jsonDna['middle']);
  91.         $this->higher = json_decode($jsonDna['higher']);
  92.     }
  93.    
  94.     public function exportJson() : array
  95.     {
  96.         return [
  97.             'lower' => json_encode($this->lower),
  98.             'middle' => json_encode($this->middle),
  99.             'higher' => json_encode($this->higher)
  100.         ];
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement