| Total Complexity | 74 |
| Total Lines | 577 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Complex classes like Zend_Gdata_Books_VolumeEntry often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Zend_Gdata_Books_VolumeEntry, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 108 | class Zend_Gdata_Books_VolumeEntry extends Zend_Gdata_Entry |
||
| 109 | { |
||
| 110 | |||
| 111 | const THUMBNAIL_LINK_REL = 'http://schemas.google.com/books/2008/thumbnail'; |
||
| 112 | const PREVIEW_LINK_REL = 'http://schemas.google.com/books/2008/preview'; |
||
| 113 | const INFO_LINK_REL = 'http://schemas.google.com/books/2008/info'; |
||
| 114 | const ANNOTATION_LINK_REL = 'http://schemas.google.com/books/2008/annotation'; |
||
| 115 | |||
| 116 | protected $_comments = null; |
||
| 117 | protected $_creators = array(); |
||
| 118 | protected $_dates = array(); |
||
| 119 | protected $_descriptions = array(); |
||
| 120 | protected $_embeddability = null; |
||
| 121 | protected $_formats = array(); |
||
| 122 | protected $_identifiers = array(); |
||
| 123 | protected $_languages = array(); |
||
| 124 | protected $_publishers = array(); |
||
| 125 | protected $_rating = null; |
||
| 126 | protected $_review = null; |
||
| 127 | protected $_subjects = array(); |
||
| 128 | protected $_titles = array(); |
||
| 129 | protected $_viewability = null; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Constructor for Zend_Gdata_Books_VolumeEntry which |
||
| 133 | * Describes an entry in a feed of Book Search volumes |
||
| 134 | * |
||
| 135 | * @param DOMElement $element (optional) DOMElement from which this |
||
| 136 | * object should be constructed. |
||
| 137 | */ |
||
| 138 | public function __construct($element = null) |
||
| 139 | { |
||
| 140 | $this->registerAllNamespaces(Zend_Gdata_Books::$namespaces); |
||
| 141 | parent::__construct($element); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Retrieves DOMElement which corresponds to this element and all |
||
| 146 | * child properties. This is used to build this object back into a DOM |
||
| 147 | * and eventually XML text for sending to the server upon updates, or |
||
| 148 | * for application storage/persistance. |
||
| 149 | * |
||
| 150 | * @param DOMDocument $doc The DOMDocument used to construct DOMElements |
||
| 151 | * @return DOMElement The DOMElement representing this element and all |
||
| 152 | * child properties. |
||
| 153 | */ |
||
| 154 | public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Creates individual objects of the appropriate type and stores |
||
| 234 | * them in this object based upon DOM data. |
||
| 235 | * |
||
| 236 | * @param DOMNode $child The DOMNode to process. |
||
| 237 | */ |
||
| 238 | protected function takeChildFromDOM($child) |
||
| 239 | { |
||
| 240 | $absoluteNodeName = $child->namespaceURI . ':' . $child->localName; |
||
| 241 | switch ($absoluteNodeName) { |
||
| 242 | case $this->lookupNamespace('dc') . ':' . 'creator': |
||
| 243 | $creators = new Zend_Gdata_DublinCore_Extension_Creator(); |
||
| 244 | $creators->transferFromDOM($child); |
||
| 245 | $this->_creators[] = $creators; |
||
| 246 | break; |
||
| 247 | case $this->lookupNamespace('dc') . ':' . 'date': |
||
| 248 | $dates = new Zend_Gdata_DublinCore_Extension_Date(); |
||
| 249 | $dates->transferFromDOM($child); |
||
| 250 | $this->_dates[] = $dates; |
||
| 251 | break; |
||
| 252 | case $this->lookupNamespace('dc') . ':' . 'description': |
||
| 253 | $descriptions = new Zend_Gdata_DublinCore_Extension_Description(); |
||
| 254 | $descriptions->transferFromDOM($child); |
||
| 255 | $this->_descriptions[] = $descriptions; |
||
| 256 | break; |
||
| 257 | case $this->lookupNamespace('dc') . ':' . 'format': |
||
| 258 | $formats = new Zend_Gdata_DublinCore_Extension_Format(); |
||
| 259 | $formats->transferFromDOM($child); |
||
| 260 | $this->_formats[] = $formats; |
||
| 261 | break; |
||
| 262 | case $this->lookupNamespace('dc') . ':' . 'identifier': |
||
| 263 | $identifiers = new Zend_Gdata_DublinCore_Extension_Identifier(); |
||
| 264 | $identifiers->transferFromDOM($child); |
||
| 265 | $this->_identifiers[] = $identifiers; |
||
| 266 | break; |
||
| 267 | case $this->lookupNamespace('dc') . ':' . 'language': |
||
| 268 | $languages = new Zend_Gdata_DublinCore_Extension_Language(); |
||
| 269 | $languages->transferFromDOM($child); |
||
| 270 | $this->_languages[] = $languages; |
||
| 271 | break; |
||
| 272 | case $this->lookupNamespace('dc') . ':' . 'publisher': |
||
| 273 | $publishers = new Zend_Gdata_DublinCore_Extension_Publisher(); |
||
| 274 | $publishers->transferFromDOM($child); |
||
| 275 | $this->_publishers[] = $publishers; |
||
| 276 | break; |
||
| 277 | case $this->lookupNamespace('dc') . ':' . 'subject': |
||
| 278 | $subjects = new Zend_Gdata_DublinCore_Extension_Subject(); |
||
| 279 | $subjects->transferFromDOM($child); |
||
| 280 | $this->_subjects[] = $subjects; |
||
| 281 | break; |
||
| 282 | case $this->lookupNamespace('dc') . ':' . 'title': |
||
| 283 | $titles = new Zend_Gdata_DublinCore_Extension_Title(); |
||
| 284 | $titles->transferFromDOM($child); |
||
| 285 | $this->_titles[] = $titles; |
||
| 286 | break; |
||
| 287 | case $this->lookupNamespace('gd') . ':' . 'comments': |
||
| 288 | $comments = new Zend_Gdata_Extension_Comments(); |
||
| 289 | $comments->transferFromDOM($child); |
||
| 290 | $this->_comments = $comments; |
||
| 291 | break; |
||
| 292 | case $this->lookupNamespace('gbs') . ':' . 'embeddability': |
||
| 293 | $embeddability = new Zend_Gdata_Books_Extension_Embeddability(); |
||
| 294 | $embeddability->transferFromDOM($child); |
||
| 295 | $this->_embeddability = $embeddability; |
||
| 296 | break; |
||
| 297 | case $this->lookupNamespace('gd') . ':' . 'rating': |
||
| 298 | $rating = new Zend_Gdata_Extension_Rating(); |
||
| 299 | $rating->transferFromDOM($child); |
||
| 300 | $this->_rating = $rating; |
||
| 301 | break; |
||
| 302 | case $this->lookupNamespace('gbs') . ':' . 'review': |
||
| 303 | $review = new Zend_Gdata_Books_Extension_Review(); |
||
| 304 | $review->transferFromDOM($child); |
||
| 305 | $this->_review = $review; |
||
| 306 | break; |
||
| 307 | case $this->lookupNamespace('gbs') . ':' . 'viewability': |
||
| 308 | $viewability = new Zend_Gdata_Books_Extension_Viewability(); |
||
| 309 | $viewability->transferFromDOM($child); |
||
| 310 | $this->_viewability = $viewability; |
||
| 311 | break; |
||
| 312 | default: |
||
| 313 | parent::takeChildFromDOM($child); |
||
| 314 | break; |
||
| 315 | } |
||
| 316 | } |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Returns the Comments class |
||
| 320 | * |
||
| 321 | * @return Zend_Gdata_Extension_Comments|null The comments |
||
| 322 | */ |
||
| 323 | public function getComments() |
||
| 324 | { |
||
| 325 | return $this->_comments; |
||
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Returns the creators |
||
| 330 | * |
||
| 331 | * @return array The creators |
||
| 332 | */ |
||
| 333 | public function getCreators() |
||
| 334 | { |
||
| 335 | return $this->_creators; |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Returns the dates |
||
| 340 | * |
||
| 341 | * @return array The dates |
||
| 342 | */ |
||
| 343 | public function getDates() |
||
| 344 | { |
||
| 345 | return $this->_dates; |
||
| 346 | } |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Returns the descriptions |
||
| 350 | * |
||
| 351 | * @return array The descriptions |
||
| 352 | */ |
||
| 353 | public function getDescriptions() |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Returns the embeddability |
||
| 360 | * |
||
| 361 | * @return Zend_Gdata_Books_Extension_Embeddability|null The embeddability |
||
| 362 | */ |
||
| 363 | public function getEmbeddability() |
||
| 364 | { |
||
| 365 | return $this->_embeddability; |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Returns the formats |
||
| 370 | * |
||
| 371 | * @return array The formats |
||
| 372 | */ |
||
| 373 | public function getFormats() |
||
| 374 | { |
||
| 375 | return $this->_formats; |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Returns the identifiers |
||
| 380 | * |
||
| 381 | * @return array The identifiers |
||
| 382 | */ |
||
| 383 | public function getIdentifiers() |
||
| 384 | { |
||
| 385 | return $this->_identifiers; |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Returns the languages |
||
| 390 | * |
||
| 391 | * @return array The languages |
||
| 392 | */ |
||
| 393 | public function getLanguages() |
||
| 394 | { |
||
| 395 | return $this->_languages; |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Returns the publishers |
||
| 400 | * |
||
| 401 | * @return array The publishers |
||
| 402 | */ |
||
| 403 | public function getPublishers() |
||
| 404 | { |
||
| 405 | return $this->_publishers; |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Returns the rating |
||
| 410 | * |
||
| 411 | * @return Zend_Gdata_Extension_Rating|null The rating |
||
| 412 | */ |
||
| 413 | public function getRating() |
||
| 414 | { |
||
| 415 | return $this->_rating; |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Returns the review |
||
| 420 | * |
||
| 421 | * @return Zend_Gdata_Books_Extension_Review|null The review |
||
| 422 | */ |
||
| 423 | public function getReview() |
||
| 424 | { |
||
| 425 | return $this->_review; |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Returns the subjects |
||
| 430 | * |
||
| 431 | * @return array The subjects |
||
| 432 | */ |
||
| 433 | public function getSubjects() |
||
| 434 | { |
||
| 435 | return $this->_subjects; |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Returns the titles |
||
| 440 | * |
||
| 441 | * @return array The titles |
||
| 442 | */ |
||
| 443 | public function getTitles() |
||
| 444 | { |
||
| 445 | return $this->_titles; |
||
| 446 | } |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Returns the viewability |
||
| 450 | * |
||
| 451 | * @return Zend_Gdata_Books_Extension_Viewability|null The viewability |
||
| 452 | */ |
||
| 453 | public function getViewability() |
||
| 454 | { |
||
| 455 | return $this->_viewability; |
||
| 456 | } |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Sets the Comments class |
||
| 460 | * |
||
| 461 | * @param Zend_Gdata_Extension_Comments|null $comments Comments class |
||
| 462 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 463 | */ |
||
| 464 | public function setComments($comments) |
||
| 465 | { |
||
| 466 | $this->_comments = $comments; |
||
| 467 | return $this; |
||
| 468 | } |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Sets the creators |
||
| 472 | * |
||
| 473 | * @param array $creators Creators|null |
||
| 474 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 475 | */ |
||
| 476 | public function setCreators($creators) |
||
| 477 | { |
||
| 478 | $this->_creators = $creators; |
||
| 479 | return $this; |
||
| 480 | } |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Sets the dates |
||
| 484 | * |
||
| 485 | * @param array $dates dates |
||
| 486 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 487 | */ |
||
| 488 | public function setDates($dates) |
||
| 489 | { |
||
| 490 | $this->_dates = $dates; |
||
| 491 | return $this; |
||
| 492 | } |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Sets the descriptions |
||
| 496 | * |
||
| 497 | * @param array $descriptions descriptions |
||
| 498 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 499 | */ |
||
| 500 | public function setDescriptions($descriptions) |
||
| 501 | { |
||
| 502 | $this->_descriptions = $descriptions; |
||
| 503 | return $this; |
||
| 504 | } |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Sets the embeddability |
||
| 508 | * |
||
| 509 | * @param Zend_Gdata_Books_Extension_Embeddability|null $embeddability |
||
| 510 | * embeddability |
||
| 511 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 512 | */ |
||
| 513 | public function setEmbeddability($embeddability) |
||
| 514 | { |
||
| 515 | $this->_embeddability = $embeddability; |
||
| 516 | return $this; |
||
| 517 | } |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Sets the formats |
||
| 521 | * |
||
| 522 | * @param array $formats formats |
||
| 523 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 524 | */ |
||
| 525 | public function setFormats($formats) |
||
| 526 | { |
||
| 527 | $this->_formats = $formats; |
||
| 528 | return $this; |
||
| 529 | } |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Sets the identifiers |
||
| 533 | * |
||
| 534 | * @param array $identifiers identifiers |
||
| 535 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 536 | */ |
||
| 537 | public function setIdentifiers($identifiers) |
||
| 538 | { |
||
| 539 | $this->_identifiers = $identifiers; |
||
| 540 | return $this; |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Sets the languages |
||
| 545 | * |
||
| 546 | * @param array $languages languages |
||
| 547 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 548 | */ |
||
| 549 | public function setLanguages($languages) |
||
| 550 | { |
||
| 551 | $this->_languages = $languages; |
||
| 552 | return $this; |
||
| 553 | } |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Sets the publishers |
||
| 557 | * |
||
| 558 | * @param array $publishers publishers |
||
| 559 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 560 | */ |
||
| 561 | public function setPublishers($publishers) |
||
| 562 | { |
||
| 563 | $this->_publishers = $publishers; |
||
| 564 | return $this; |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Sets the rating |
||
| 569 | * |
||
| 570 | * @param Zend_Gdata_Extension_Rating|null $rating rating |
||
| 571 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 572 | */ |
||
| 573 | public function setRating($rating) |
||
| 574 | { |
||
| 575 | $this->_rating = $rating; |
||
| 576 | return $this; |
||
| 577 | } |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Sets the review |
||
| 581 | * |
||
| 582 | * @param Zend_Gdata_Books_Extension_Review|null $review review |
||
| 583 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 584 | */ |
||
| 585 | public function setReview($review) |
||
| 586 | { |
||
| 587 | $this->_review = $review; |
||
| 588 | return $this; |
||
| 589 | } |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Sets the subjects |
||
| 593 | * |
||
| 594 | * @param array $subjects subjects |
||
| 595 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 596 | */ |
||
| 597 | public function setSubjects($subjects) |
||
| 598 | { |
||
| 599 | $this->_subjects = $subjects; |
||
| 600 | return $this; |
||
| 601 | } |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Sets the titles |
||
| 605 | * |
||
| 606 | * @param array $titles titles |
||
| 607 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 608 | */ |
||
| 609 | public function setTitles($titles) |
||
| 610 | { |
||
| 611 | $this->_titles = $titles; |
||
| 612 | return $this; |
||
| 613 | } |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Sets the viewability |
||
| 617 | * |
||
| 618 | * @param Zend_Gdata_Books_Extension_Viewability|null $viewability |
||
| 619 | * viewability |
||
| 620 | * @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface |
||
| 621 | */ |
||
| 622 | public function setViewability($viewability) |
||
| 623 | { |
||
| 624 | $this->_viewability = $viewability; |
||
| 625 | return $this; |
||
| 626 | } |
||
| 627 | |||
| 628 | |||
| 629 | /** |
||
| 630 | * Gets the volume ID based upon the atom:id value |
||
| 631 | * |
||
| 632 | * @return string The volume ID |
||
| 633 | * @throws Zend_Gdata_App_Exception |
||
| 634 | */ |
||
| 635 | public function getVolumeId() |
||
| 636 | { |
||
| 637 | $fullId = $this->getId()->getText(); |
||
| 638 | $position = strrpos($fullId, '/'); |
||
| 639 | if ($position === false) { |
||
| 640 | require_once 'Zend/Gdata/App/Exception.php'; |
||
| 641 | throw new Zend_Gdata_App_Exception('Slash not found in atom:id'); |
||
| 642 | } else { |
||
| 643 | return substr($fullId, strrpos($fullId,'/') + 1); |
||
| 644 | } |
||
| 645 | } |
||
| 646 | |||
| 647 | /** |
||
| 648 | * Gets the thumbnail link |
||
| 649 | * |
||
| 650 | * @return Zend_Gdata_App_Extension_link|null The thumbnail link |
||
| 651 | */ |
||
| 652 | public function getThumbnailLink() |
||
| 653 | { |
||
| 654 | return $this->getLink(self::THUMBNAIL_LINK_REL); |
||
|
|
|||
| 655 | } |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Gets the preview link |
||
| 659 | * |
||
| 660 | * @return Zend_Gdata_App_Extension_Link|null The preview link |
||
| 661 | */ |
||
| 662 | public function getPreviewLink() |
||
| 665 | } |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Gets the info link |
||
| 669 | * |
||
| 670 | * @return Zend_Gdata_App_Extension_Link|null The info link |
||
| 671 | */ |
||
| 672 | public function getInfoLink() |
||
| 673 | { |
||
| 674 | return $this->getLink(self::INFO_LINK_REL); |
||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Gets the annotations link |
||
| 679 | * |
||
| 680 | * @return Zend_Gdata_App_Extension_Link|null The annotations link |
||
| 681 | */ |
||
| 682 | public function getAnnotationLink() |
||
| 683 | { |
||
| 684 | return $this->getLink(self::ANNOTATION_LINK_REL); |
||
| 685 | } |
||
| 686 | |||
| 687 | } |
||
| 688 |