fork download
  1. <?php
  2. // Cole Class
  3. namespace Marshall;
  4.  
  5. class Cole {
  6. const NAME_FIRST = "Cole";
  7. const NAME_LAST = "Marshall";
  8. private $profession;
  9. private $specialties;
  10.  
  11. function __construct($initialProfession = "Interactive Developer & Designer") {
  12. $this->profession = $initialProfession;
  13. $this->specialties = [
  14. "HTML", "CSS", "JavaScript", "Sass", "Vue.js", "jQuery",
  15. "cross-browser compatibility", "mobile/responsive design", "search engine optimization",
  16. "PHP", "MySQL", "REST", "XML", "JSON", "Git", "automation",
  17. "Photoshop", "Illustrator", "XD", "After Effects", "Graphic Design", "Typography",
  18. "User Interface (UI) Design", "User Experience (UX) Design", "Motion Graphics"
  19. ];
  20. }
  21.  
  22. public function getFullName() {
  23. return self::NAME_FIRST . ' ' . self::NAME_LAST;
  24. }
  25.  
  26. public function getProfession() {
  27. return $this->profession;
  28. }
  29.  
  30. public function setProfession($newProfession) {
  31. return $this->profession = $newProfession;
  32. }
  33.  
  34. public function getSpecialties() {
  35. return $this->specialties;
  36. }
  37.  
  38. public function setSpecialties($newSpecialties) {
  39. if (is_array($newSpecialties)) {
  40. return $this->specialties = $newSpecialties;
  41. } else {
  42. return false;
  43. }
  44. }
  45.  
  46. public function getReadableDetails() {
  47. $readable = $this->getFullName() . " is " . (preg_match('/^[aeiou]/i',$this->getProfession())?"an ":"a ") . $this->getProfession() . " who specializes in ";
  48. for ($i = 0; $i < count($this->getSpecialties()); $i++) {
  49. $readable .= $this->getSpecialties()[$i];
  50. if ($i == count($this->getSpecialties()) - 2) {
  51. $readable .= (count($this->getSpecialties()) > 2?",":'') . " and ";
  52. } else if ($i == count($this->getSpecialties()) - 1) {
  53. $readable .= ".";
  54. } else {
  55. $readable .= ", ";
  56. }
  57. }
  58. return $readable;
  59. }
  60. }
  61.  
  62. // Instantiate Cole
  63. $cole = new \Marshall\Cole();
  64.  
  65. // Echo Cole's Profession and Specialties
  66. echo $cole->getReadableDetails();
Success #stdin #stdout 0.02s 26608KB
stdin
Standard input is empty
stdout
Cole Marshall is an Interactive Developer & Designer who specializes in HTML, CSS, JavaScript, Sass, Vue.js, jQuery, cross-browser compatibility, mobile/responsive design, search engine optimization, PHP, MySQL, REST, XML, JSON, Git, automation, Photoshop, Illustrator, XD, After Effects, Graphic Design, Typography, User Interface (UI) Design, User Experience (UX) Design, and Motion Graphics.