Exemple #1
0
 public function test_first_last_count()
 {
     $arc = new ArrayCollection(array('aap', 'aap', 'noot', 'mies'));
     $this->assertEquals($arc->first(), 'aap');
     $this->assertEquals($arc->last(), 'mies');
     $this->assertEquals($arc->count(), 4);
 }
 /**
  * @return float consumption per 100km
  */
 public function getAverageConsumption()
 {
     $count = $this->refuels->count();
     if (!$count) {
         return;
     }
     $sum = 0;
     $this->refuels->map(function (Refuel $refuel) use(&$sum) {
         $sum += $refuel->getConsumption();
     });
     return $sum / $count;
 }
Exemple #3
0
 public function getRoles()
 {
     if (!$this->roles->count()) {
         return array(parent::ROLE_DEFAULT);
     }
     $roles = $this->roles->toArray();
     foreach ($this->getGroups() as $group) {
         $roles = array_merge($roles, $group->getRoles());
     }
     foreach ($roles as $k => $role) {
         /*
          * Ensure String[] to prevent bad unserialized UsernamePasswordToken with for instance
          * UPT#roles:{Role('ROLE_USER'), 'ROLE_USER'} which ends in Error: Call to a member
          * function getRole() on a non-object
          */
         $roles[$k] = $role instanceof RoleInterface ? $role->getRole() : (string) $role;
     }
     return array_flip(array_flip($roles));
 }
 /**
  * Finalize the block; mark it closed for modification
  *
  * @param int          $lineNumber
  * @param InlineParser $inlineParser
  * @param ReferenceMap $refMap
  */
 public function finalize($lineNumber, CommonMark_InlineParser $inlineParser, CommonMark_Reference_ReferenceMap $refMap)
 {
     if (!$this->open) {
         return;
     }
     $this->open = false;
     if ($lineNumber > $this->startLine) {
         $this->endLine = $lineNumber - 1;
     } else {
         $this->endLine = $lineNumber;
     }
     switch ($this->getType()) {
         case self::TYPE_PARAGRAPH:
             $this->stringContent = preg_replace('/^  */m', '', implode("\n", $this->strings->toArray()));
             // Try parsing the beginning as link reference definitions:
             while ($this->stringContent[0] === '[' && ($pos = $inlineParser->parseReference($this->stringContent, $refMap))) {
                 $this->stringContent = substr($this->stringContent, $pos);
                 if ($this->isStringContentBlank()) {
                     //RegexHelper::getInstance()->isBlank($this->stringContent)) {
                     $this->type = self::TYPE_REFERENCE_DEF;
                     break;
                 }
             }
             break;
         case self::TYPE_ATX_HEADER:
         case self::TYPE_SETEXT_HEADER:
         case self::TYPE_HTML_BLOCK:
             $this->stringContent = implode("\n", $this->strings->toArray());
             break;
         case self::TYPE_INDENTED_CODE:
             $reversed = array_reverse($this->strings->toArray(), true);
             foreach ($reversed as $index => $line) {
                 if ($line == '' || $line === "\n" || preg_match('/^(\\n *)$/', $line)) {
                     unset($reversed[$index]);
                 } else {
                     break;
                 }
             }
             $fixed = array_reverse($reversed);
             $tmp = implode("\n", $fixed);
             if (substr($tmp, -1) !== "\n") {
                 $tmp .= "\n";
             }
             $this->stringContent = $tmp;
             break;
         case self::TYPE_FENCED_CODE:
             // first line becomes info string
             $this->setExtra('info', CommonMark_Util_RegexHelper::unescape(trim($this->strings->first())));
             if ($this->strings->count() == 1) {
                 $this->stringContent = '';
             } else {
                 $this->stringContent = implode("\n", $this->strings->slice(1)) . "\n";
             }
             break;
         case self::TYPE_LIST:
             $this->setExtra('tight', true);
             // tight by default
             $numItems = $this->children->count();
             $i = 0;
             while ($i < $numItems) {
                 /** @var BlockElement $item */
                 $item = $this->children->get($i);
                 // check for non-final list item ending with blank line:
                 $lastItem = $i == $numItems - 1;
                 if ($item->endsWithBlankLine() && !$lastItem) {
                     $this->setExtra('tight', false);
                     break;
                 }
                 // Recurse into children of list item, to see if there are
                 // spaces between any of them:
                 $numSubItems = $item->getChildren()->count();
                 $j = 0;
                 while ($j < $numSubItems) {
                     $subItem = $item->getChildren()->get($j);
                     $lastSubItem = $j == $numSubItems - 1;
                     if ($subItem->endsWithBlankLine() && !($lastItem && $lastSubItem)) {
                         $this->setExtra('tight', false);
                         break;
                     }
                     $j++;
                 }
                 $i++;
             }
             break;
         default:
             break;
     }
 }
 /** {@inheritDoc} */
 public function count()
 {
     $this->initialize();
     return $this->collection->count();
 }
Exemple #6
0
 public function __toString()
 {
     return "Id: " . $this->id . " - Entries: " . $this->entries->count() . " - Owner: " . $this->getOwnerName();
 }